Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

我的代妈用C++会CE。。。G++能过(在北京西站猴车室刷的mark)

Posted by KatrineYang at 2016-07-06 02:03:02 on Problem 1056
//============================================================================
// Name        : main1056.cpp
// Author      : 
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <vector>
using namespace std;

class node{
public:
	node *left;
	node *right;
	bool isLeaf;
	node(){left = NULL; right = NULL; isLeaf = false;}
};


node *root;

int main() {
	int cnt = 0;
	string s;
	vector<string> vec;
	while(getline(cin, s)){
		if(s != "9"){
			vec.push_back(s);
			continue;
		}
		cnt ++;
		cout << "Set " << cnt << " is ";
		int size = vec.size();
		root = new node();
		bool dec = true;
		for(int i = 0; i < size; i++){
			string st = vec[i];
			int len = st.length();
			node *curN = root;
			for(int j = 0; j < len; j++){
				if(st[j] == '0'){
					if(curN->left == NULL){
						node *temp = new node();
						curN->left = temp;
						curN = curN->left;
					}
					else{
						curN = curN->left;
					}
				}
				else{
					if(curN->right == NULL){
						node *temp = new node();
						curN->right = temp;
						curN = curN->right;
					}
					else{
						curN = curN->right;
					}
				}
				if(curN->isLeaf) {
					dec = false;
					break;
				}
				//curN->isLeaf = true;
			}
			if(!dec) break;
			curN->isLeaf = true;
		}
		if(!dec){
			cout << "not immediately decodable" << endl;
		}
		else{
			cout << "immediately decodable" << endl;
		}
		vec.clear();
	}
	//cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator