fork download
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define MO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  4. #define ll long long
  5. int q;
  6. string old , nw;
  7. map<string,string>mp;
  8. int main()
  9. {
  10. MO
  11. cin>>q;
  12. while(q--)
  13. {
  14. cin>>old>>nw;
  15. auto it = mp.find(old);
  16. if(it!=mp.end())
  17. {
  18. old = it->second;
  19. mp.erase(it);
  20. }
  21. mp[nw]=old;
  22. }
  23. cout<<mp.size()<<'\n';
  24. for(auto it : mp)
  25. cout<<it.second<<' '<<it.first<<'\n';
  26. return 0;
  27. }
  28.  
Success #stdin #stdout 0.01s 5520KB
stdin
Standard input is empty
stdout
0