-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabc.cpp
69 lines (56 loc) · 1.11 KB
/
abc.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
/**
* French Australian Regional Informatics Olympiad 2010, Q2
* Ananya Kumar, 2012
* NUS High School
*/
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
vector<string> dic[21];
char next[256];
int N, M;
bool found;
int main ()
{
int i, j, k;
string tmps;
scanf("%d",&N);
//dic.assign(N,"");
for ( i = 0; i < N; i++ )
{
cin >> tmps;
dic[tmps.size()].push_back(tmps);
}
for ( i = 0; i < 21; i++ ) sort(dic[i].begin(),dic[i].end());
scanf("%d",&M);
for ( i = 'a'; i < 'z'; i++ ) next[i] = i+1;
next['z'] = 'a';
while ( M-- )
{
cin >> tmps;
found = false;
if ( binary_search(dic[tmps.size()].begin(),dic[tmps.size()].end(),tmps) )
{
cout << tmps << endl;
continue;
}
for ( j = 0; j < tmps.size(); j++ )
{
tmps[j] = next[tmps[j]];
for ( k = 0; k < 25; k++ )
{
if ( binary_search(dic[tmps.size()].begin(),dic[tmps.size()].end(),tmps) )
{
cout << tmps << endl;
found = true;
break;
}
tmps[j] = next[tmps[j]];
}
if ( found ) break;
}
if ( !found ) cout << "?" << endl;
}
}