Salvens

G

Jul 27th, 2023
831
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.78 KB | None | 0 0
  1. #include <array>
  2. #include <iostream>
  3. #include <vector>
  4. #include <map>
  5.  
  6. using namespace std;
  7.  
  8. #define int long long
  9.  
  10. const long long INF = 1e18 + 7;
  11. const int MAXN = 2e5 + 10;
  12. const int N = 2e5;
  13.  
  14. signed main() {
  15.     ios_base::sync_with_stdio(false);
  16.     cin.tie(nullptr);
  17.     cout.tie(nullptr);
  18.     int n;
  19.     cin >> n;
  20.     map<string, string> start, tmp;
  21.     for (int i = 0; i < n; ++i) {
  22.         string old, nw;
  23.         cin >> old >> nw;
  24.         if (!tmp.contains(old)) {
  25.             start[old] = nw;
  26.             tmp[nw] = old;
  27.         } else {
  28.             string cur = tmp[old];
  29.             start[cur] = nw;
  30.             tmp[nw] = cur;
  31.         }
  32.     }
  33.     cout << start.size() << '\n';
  34.     for (auto& [x, y]: start) {
  35.         cout << x << ' ' << y << '\n';
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment