Advertisement
Saleh127

UVA 200

Jul 6th, 2021
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define endl "\n"
  5. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  6. stack<char>ans;
  7. vector<char>g[20000];
  8. bool v[20000];
  9. map<char,ll>x;
  10.  
  11. void dfs(char c)
  12. {
  13. if(v[c]) return;
  14.  
  15. v[c]=1;
  16.  
  17. for(auto dd:g[c])
  18. {
  19. if(v[dd]==0)
  20. {
  21. dfs(dd);
  22. }
  23. }
  24.  
  25. ans.push(c);
  26. }
  27.  
  28. int main()
  29. {
  30. ios_base::sync_with_stdio(0);
  31. cin.tie(0);cout.tie(0);
  32.  
  33. string a,b;
  34. ll i,j,k,l;
  35.  
  36. cin>>a;
  37.  
  38. while(cin>>b)
  39. {
  40. if(b=="#") break;
  41.  
  42. for(i=0;i<min(a.size(),b.size());i++)
  43. {
  44. if(a[i]!=b[i])
  45. {
  46. x[a[i]]=1;
  47. x[v[i]]=1;
  48. g[a[i]].push_back(b[i]);
  49. break;
  50. }
  51. }
  52. a=b;
  53. }
  54.  
  55. for(char s='A';s<='Z';s++)
  56. {
  57. if(v[s]==0 && x[s]==1)
  58. {
  59. dfs(s);
  60. }
  61. }
  62.  
  63. while(ans.empty()==false)
  64. {
  65. cout<<ans.top();
  66. ans.pop();
  67. }
  68. cout<<endl;
  69.  
  70. return 0;
  71. }
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement