fork(1) download
  1. #include <iostream>
  2. #include <vector>
  3. #include <map>
  4. using namespace std;
  5.  
  6. template <typename T>
  7. std::ostream &operator<<(std::ostream &os, const std::vector<T> &vec) {
  8. os << '{';
  9. for(size_t x = 0; x + 1 < vec.size(); x++) {
  10. os << vec.at(x) << ", ";
  11. }
  12. if(vec.size() > 0) os << vec.at(vec.size()-1);
  13. os << '}';
  14. return os;
  15. }
  16.  
  17.  
  18. int main() {
  19. int n, m;
  20. // your code goes here
  21. std::map<int, std::vector<int>> arr;
  22. while(cin>>n>>m){
  23. arr[n].push_back(m); //push m onto row n
  24. }
  25.  
  26. for(auto x : arr) {
  27. cout << x.first << ' ' << x.second << endl;
  28. }
  29. return 0;
  30. }
Success #stdin #stdout 0s 4416KB
stdin
0 0
0 1
0 2
0 3
1 1
1 4
2 1
2 4
2 3
stdout
0 {0, 1, 2, 3}
1 {1, 4}
2 {1, 4, 3}