#include <iostream>
#include <string>
#include <cstring>
using namespace std;
int k;
typedef structnode
{
int num;
structnode *next[10];
}node;
nodememory[1000000];
int insert(char *s, node*T)
{
int len = 0;
int id = 0;
node*p,*q;
p = T;
len = strlen(s);
for(int i = 0 ; i < len; i++)
{
id = s[i] - '0';
if(p->num == 1)
return 1;
if(p->next[id] == NULL)
{
q = &memory[k++];
q->num = 0;
for(int j = 0; j < 10; j++)
{
q->next[j] = NULL;
}
p->next[id] = q;
}
p = p->next[id];
}
for(int i = 0 ; i < 10; i++)
{
if(p->next[i] != NULL)
return 1;
}
p->num = 1;
return 0;
}
int main()
{
int t;
node*T;
cin>>t;
while(t)
{
k = 0;
T = &memory[k++];
T->num = 0;
for(int i = 0 ; i < 10; i++)
{
T->next[i] = NULL;
}
int flag = 0;
int n;
cin>>n;
for(int i = 0 ; i < n ; i++)
{
char s[15];
cin>>s;
if(flag)
continue;
if(insert(s,T))
flag = 1;
}
if(flag)
cout<<"NO"<<endl;
else
cout<<"YES"<<endl;
t--;
}
return 0;
}
转载于:https://www.cnblogs.com/T8023Y/p/3255107.html