题目链接:登录—专业IT笔试面试备考平台_牛客网
AC代码:
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+10;
const int M=15;
int trie[N][30],tot=1;
int ansend[N];
int fg,f;
void insert(string str)
{
int len=str.size(),p=0;
for(int k=0;k<len;k++)
{
int ch=str[k]-'0';
if(!trie[p][ch])trie[p][ch]=tot++,fg=1;
if(ansend[trie[p][ch]])f=0;
p=trie[p][ch];
}
ansend[p]=1;
}
int main()
{
int t;
cin >> t;
while(t--)
{
tot=1;
memset(trie,0,sizeof(trie));
memset(ansend,0,sizeof(ansend));
int n;
cin >> n;
int fgg=0;
for(int i=1;i<=n;i++)
{
fg=0,f=1;
string s;
cin >> s;
insert(s);
if(!fg||!f)fgg=1;
}
if(fgg==1)
cout << "NO" << endl;
else
cout << "YES" << endl;
}
return 0;
}