The difficulty of this question is similar to that of the previous bare template.
Check whether the string is the prefix of another string,
Check whether the count of the last node is 1 in the dictionary tree.
If the value is 1, the string is unique.
If it is not unique, it indicates that the string is completely contained by other strings. Isn't it a prefix!
Water over...
#include<iostream>#include<string>#include<cstdio>#define MAX 10using namespace std;char s[11111][11];int allocp;struct TireNode{ int nCount; TireNode *next[MAX];};TireNode Memeroy[1111111];void InitTire( TireNode **root ){ *root=NULL;}TireNode *CreateTire(){ int i; TireNode *p=&Memeroy[allocp++]; p->nCount=1; for( int i=0;i<MAX;i++ ) p->next[i]=NULL; return p;}void InsertTire( TireNode **root,char *s ){ int i=0,k; TireNode *p; if( !(p=*root) ) p=*root=CreateTire(); while( s[i] ) { k=s[i++]-'0'; if( p->next[k] ) p->next[k]->nCount++; else p->next[k]=CreateTire(); p=p->next[k]; }}bool SearchTire( TireNode **root,char *s ){ int i=0,k; TireNode *p=*root; int cnt=0; while( s[i] ) { k=s[i++]-'0'; cnt=p->next[k]->nCount; p=p->next[k]; } if( cnt==1 ) return false; else return true; }int main(){ int T; scanf( "%d",&T ); while( T-- ) { allocp=0; TireNode *root; root=NULL; int len=0; scanf( "%d",&len ); for( int i=0;i<len;i++ ) { scanf( "%s",&s[i] ); InsertTire(&root,s[i]); } bool found=true; for( int i=0;i<len;i++ ) { if( SearchTire(&root,s[i]) ) { found=false; break;} } if( found==false ) printf( "NO\n" ); else printf( "YES\n" ); } return 0;}