-
Notifications
You must be signed in to change notification settings - Fork 0
/
11362-phonelist.cpp
89 lines (78 loc) · 1.6 KB
/
11362-phonelist.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Rodrigo Farias de Macêdo
#include <string>
#include <iostream>
#include <cstdio>
#include <stdlib.h>
#include <sstream>
#include <cctype>
#include <algorithm>
#include <utility>
#include <iterator>
#include <math.h>
#include <set>
#include <map>
#include <vector>
#include <queue>
using namespace std;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
map<char, long long> hash;
void iniciamapa(){
hash['0'] = 1; hash['1'] = 2; hash['2'] = 3; hash['3'] = 4; hash['4'] = 5; hash['5'] = 6; hash['6'] = 7 ;hash['7'] = 8 ; hash['8'] = 9; hash['9'] = 10;
}
//int int_mod(int a, int b){
// return (a%b +b) &b;
//}
int geraHash(string text, int m){
int hasha = 0, base = 11, mod = 179424673;
for(int i = 0; i< m; i++){
int aux = hash[text[i]] * pow(base, i);
hasha += aux % mod;
}
return hasha%mod;
}
int main(){
//std::ios_base::sync_with_stdio(false);
iniciamapa();
int test, phones;
cin >> test;
string word;
for(int a = 0; a < test; a++){
cin>> phones;
bool continua = true;
map<int, int> hashs;
vector<string> words;
for (int b = 0; b<phones;b++){
cin >> word;
int i=0;
while (word[i]){
i++;
}
words.push_back(word);
}
for(int p = 1; p<11;p++){
for (int b = 0; b<phones;b++){
word = words[b];
if(word.size() == p){
int i=0;
int j;
while (word[i]){
i++;
j = geraHash(word, i);
if(hashs[j] ==1){
continua = false;
break;
}
}
hashs[j] =1;
}
}
}
if(continua){
cout <<"YES"<<endl;
}else{
cout << "NO" << endl;
}
}
}