fork download
  1. #include <bits/stdc++.h>
  2. typedef long long ll;
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7. ll n, t;
  8. cin>>t;
  9. while(t--)
  10. {
  11. cin>>n;
  12. unordered_map<string, ll>u_map;
  13. // unordered_map<string, string>u_map2;
  14. vector<pair<string, string> > V;
  15.  
  16. string s1, s2;
  17.  
  18. while(n--)
  19. {
  20. cin>>s1;
  21. u_map[s1]++;
  22. cin>>s2;
  23. // u_map2[s2] = s1+" "+s2;
  24. V.push_back({s1, s2});
  25. }
  26.  
  27. for( auto u:V)
  28. {
  29. if(u_map[u.first]>1)
  30. {
  31. cout<<u.first<<" "<<u.second<<endl;
  32. }
  33.  
  34. else
  35. {
  36. cout<<u.first<<endl;
  37. }
  38. }
  39.  
  40. }
  41.  
  42. return 0;
  43. }
Success #stdin #stdout 0s 4368KB
stdin
1
4
hasan jaddouh
farhod khakimiyon
kerim kochekov
hasan khateeb
stdout
hasan jaddouh
farhod
kerim
hasan khateeb