-
Notifications
You must be signed in to change notification settings - Fork 0
/
11362.cpp
37 lines (34 loc) · 852 Bytes
/
11362.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <cstdio>
#include <iostream>
#include <set>
#include <string>
inline bool is_consistent(const std::string& str, const std::set<std::string>& dictionary) {
for(int i=1; i<str.length(); ++i) {
std::string prefix = str.substr(0, i);
if(dictionary.find(prefix)!=dictionary.end()) {
return false;
}
}
return true;
}
int t, n;
int main() {
scanf("%d", &t);
while(t--) {
std::set<std::string> numbers;
scanf("%d\n", &n);
while(n--) {
std::string number;
getline(std::cin, number);
numbers.insert(number);
}
bool consist = true;
for(std::set<std::string>::iterator it=numbers.begin(); it!=numbers.end(); it++) {
consist = is_consistent(*it, numbers);
if(!consist) {
break;
}
}
printf( consist ? "YES\n" : "NO\n");
}
}