Dang_Quan_10_Tin

Untitled

May 9th, 2020
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.93 KB | None | 0 0
  1. #include <iostream>
  2. #include <queue>
  3. #include <vector>
  4. #include <cstdio>
  5. #define task "PAINT"
  6. using namespace std;
  7. using ll = long long;
  8. using ld = long double;
  9.  
  10. const int N = 30 + 2;
  11. const int M = 1e6 + 1;
  12. int n, m(0);
  13. queue<int> s;
  14. vector<int> v[N];
  15. char c[M];
  16.  
  17. void Read(){
  18.     cin >> n;
  19.     for(int i = 1; i <= n; ++i)
  20.         s.push(i);
  21.     while(n--){
  22.         int t; cin >> t;
  23.         if(t == 1){
  24.             m = max(m, s.front());
  25.             char a; cin >> a;
  26.             c[s.front()] = a;
  27.             v[a - 'a'].push_back(s.front());
  28.             s.pop();
  29.         }
  30.         else{
  31.             char a, b;
  32.             cin >> a >> b;
  33.             if(a != b){
  34.                 for(auto i : v[a - 'a'])
  35.                     v[b - 'a'].push_back(i), c[i] = b;
  36.                 v[a - 'a'].clear();
  37.             }
  38.         }
  39.     }
  40. }
  41.  
  42. void Solve(){
  43.     for(int i = 1; i <= m; ++i)
  44.         cout << c[i];
  45. }
  46.  
  47. main(){
  48.     ios::sync_with_stdio(0);
  49.     cin.tie(0);
  50.     cout.tie(0); if(fopen(task".INP", "r"))
  51.     freopen(task".INP", "r", stdin),
  52.     freopen(task".OUT", "w", stdout);
  53.     Read();
  54.     Solve();
  55. }
Advertisement
Add Comment
Please, Sign In to add comment