-
Notifications
You must be signed in to change notification settings - Fork 0
/
UvA 2000.cpp
57 lines (44 loc) · 1 KB
/
UvA 2000.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
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
int visited[26];
vector <int> visit;
int main(){
string s;
cin>>s;
vector <vector <int> > adj_list(26+1);
string t;
map <int, int> track;
while(cin>>t){
if(t=="#") break;
for(int i=0; i<min(t.size(),s.size()); i++){
if(s[i]!=t[i]){
adj_list[s[i]-'A'].pb(t[i]-'A');
if(track.count(s[i]-'A')==0){
track[s[i]-'A']=0;
}
track[t[i]-'A']++;
break;
}
}
s=t;
}
vector <char> ans;
while(ans.size()<track.size()){
for(auto &x: track){
if (x.second==0){
ans.pb(x.first+'A');
x.second=-1;
for(int pp: adj_list[x.first]){
track[pp]--;
}
break;
}
}
}
for(char x:ans){
cout<<x;
}
cout<<endl;
return 0;
}