-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy path1056(Cypher,Tree)
75 lines (70 loc) · 1.27 KB
/
1056(Cypher,Tree)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#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;
}