标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2248 Accepted Submission(s):
1168
点我
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 using namespace std; 5 #define max 2 6 typedef struct TrieNode 7 { 8 int ncount; 9 struct TrieNode *next[max]; 10 }TrieNode; 11 TrieNode* createTrieNode() 12 { 13 TrieNode* temp=new TrieNode; 14 temp->ncount=0; 15 for(int i=0;i<max;i++) 16 temp->next[i]=NULL; 17 return temp; 18 } 19 void insertTrie(TrieNode* proot,char* str) 20 { 21 TrieNode *temp=proot; 22 for(int i=0;str[i];i++) 23 { 24 int t=str[i]-‘0‘; 25 if(temp->next[t]==NULL) 26 temp->next[t]=createTrieNode(); 27 temp=temp->next[t]; 28 temp->ncount++; 29 } 30 } 31 int searchTrie(TrieNode* p,char *str) 32 { 33 for(int i=0;str[i];i++) 34 { 35 int t=str[i]-‘0‘; 36 p=p->next[t]; 37 if(!p) 38 return 0; 39 } 40 return p->ncount; 41 } 42 int main() 43 { 44 char a[99][100]; 45 int i=0,k=1; 46 TrieNode* root=createTrieNode(); 47 while(gets(a[i])) 48 { 49 int count=0; 50 while(a[i][0]!=‘9‘) 51 { 52 insertTrie(root,a[i]); 53 i++; 54 gets(a[i]); 55 } 56 count=i; 57 for(i=0;i<count;i++) 58 { 59 if(searchTrie(root,a[i])!=1) 60 { 61 cout<<"Set "<<k++<<" is not immediately decodable"<<endl; 62 break; 63 } 64 } 65 if(i==count) 66 cout<<"Set "<<k++<<" is immediately decodable"<<endl; 67 i=0; 68 } 69 }
标签:
原文地址:http://www.cnblogs.com/a1225234/p/4672805.html