-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathalphabetanimals.cpp
More file actions
49 lines (44 loc) · 943 Bytes
/
alphabetanimals.cpp
File metadata and controls
49 lines (44 loc) · 943 Bytes
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
#include <bits/stdc++.h>
#include <unordered_set>
#include <unordered_map>
using namespace std;
#define ar array
#define ll long long
void solve() {
string start;
cin>>start;
int n;
cin>>n;
unordered_map<char, vector<string> > m;
while(n--){
string w;
cin>>w;
m[w[0]].push_back(w);
}
char start_last=start.back();
if(m[start_last].empty()){
cout<<"?"<<endl;
return;
}
for(string w:m[start_last]){
bool elim=(
w.back()==w.front()&&(m[w.back()].size()==1)
||m[w.back()].empty()
);
if(elim){
cout<<w<<"!"<<endl;
return;
}
}
cout<<m[start_last][0]<<endl;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int tc = 1;
// cin >> tc;
for (int t = 1; t <= tc; t++) {
// cout << "Case #" << t << ": ";
solve();
}
}