Phone List
程序员文章站
2022-06-02 19:47:37
...
#include <bits/stdc++.h>
using namespace std;
const int SIZE = 1e5 + 10;
int trie[SIZE][10], sign[SIZE], tot = 1;
char ss[SIZE][20];
void insert(char* str) {
int len = strlen(str), p = 1;
for (int i = 0; i < len; ++i) {
int ch = str[i] - '0';
if (!trie[p][ch]) trie[p][ch] = ++tot;
p = trie[p][ch];
}
sign[p]++;
}
bool search(char* str) {
int len = strlen(str), p = 1;
for(int i = 0; i < len; ++i) {
int ch = str[i] - '0';
if (sign[p]) return true;
p = trie[p][ch];
}
return false;
}
bool solve(int n) {
for (int i = 1; i <= n; ++i) insert(ss[i]);
for (int i = 1; i <= n; ++i) {
if (search(ss[i])) return true;
}
return false;
}
int main() {
int T; cin >> T;
while (T--) {
int n; cin >> n;
for (int i = 1; i <= n; ++i) scanf("%s",ss[i]);
if (solve(n)) puts("NO");
else puts("YES");
memset(trie,0,sizeof(trie));
memset(sign,false,sizeof(sign));
tot = 1;
}
return 0;
}
下一篇: 怎样去鱼臭味比较好?三个方法告诉你