fork download
  1. #include<iostream>
  2. #include<map>
  3. #include<set>
  4. #include<string>
  5. #include<vector>
  6. #include<algorithm>
  7.  
  8. using namespace std;
  9.  
  10. int main() {
  11. int N;
  12. cin >> N;
  13.  
  14. map<string, set<string>> xs;
  15.  
  16. for(int i=0; i<N; i++){
  17. string k, v;
  18. cin >> k >> v;
  19. xs[k].insert(v);
  20. }
  21.  
  22. for_each(xs.begin(), xs.end(), [xs](auto& it){
  23. cout << it.first << "," << *(xs.at(it.first).begin()) << endl;
  24. });
  25.  
  26. return 0;
  27. }
Success #stdin #stdout 0s 4652KB
stdin
6
c e
b c
c f
b d
a b
c g
stdout
a,b
b,c
c,e