Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int flag=0;
- struct node
- {
- bool endmark;
- node *next[10];
- node()
- {
- endmark=false;
- for(int i=0; i<10; i++)
- next[i]=NULL;
- }
- }*root;
- void insert(char *str,int len)
- {
- node *curr=root;
- for(int i=0; i<len; i++)
- {
- int id=str[i]-'0';
- if(curr->next[id]==NULL)
- curr->next[id]=new node();
- curr=curr->next[id];
- if(curr->endmark==1)
- flag=1;
- }
- curr->endmark=1;
- }
- void del(node *cur)
- {
- for(int i=0; i<10; i++) if(cur->next[i])
- del(cur->next[i]) ;
- delete(cur) ;
- }
- int main()
- {
- root=new node();
- int num_word,j=1,T;
- cin>>T;
- while(T--)
- {
- flag=0;
- cin>>num_word;
- for(int i=1; i<=num_word; i++)
- {
- char str[50];
- scanf("%s",str);
- insert(str,strlen(str));
- }
- if(flag==1)
- cout<<"Case "<<j<<": NO"<<endl;
- else
- cout<<"Case "<<j<<": YES"<<endl;
- j++;
- del(root);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement