Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <sstream>
- using namespace std;
- struct node
- {
- int ch[10];
- bool isword;
- };
- long long ar[10005];
- int nodecount;
- struct node trie[20000];
- void init()
- {
- nodecount=1;
- }
- string stringki(long long a)
- {
- string ans;
- stringstream ss;
- ss << a;
- ans=ss.str();
- return ans;
- }
- int t,n;
- bool ans;
- string temp;
- bool trie_insert(string s)
- {
- int next,cur=1;
- for(int i=0;i<s.size();i++)
- {
- int letter=s[i]-'0';
- next=trie[cur].ch[letter];
- if(next==0)
- {
- nodecount++;
- trie[cur].ch[letter]=nodecount;
- cur=nodecount;
- }
- else
- {
- cur=next;
- }
- if(trie[cur].isword)
- {
- return true;
- }
- }
- trie[cur].isword=true;
- return false;
- }
- int main()
- {
- cin>>t;
- for(int kz=0;kz<t;kz++)
- {
- init();
- cin>>n;
- for(int i=0;i<n;i++)
- {
- cin>>ar[i];
- }
- sort(ar,ar+n);
- for(int i=0;i<n;i++)
- {
- temp=stringki(ar[i]);
- cout<<temp<<endl;
- ans=trie_insert(temp);
- cout<<ans<<endl;
- if(ans)
- {
- cout<<"NO\n";
- break;
- }
- if(i==n-1)
- {
- cout<<"YES\n";
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement