fork(1) download
  1. #include <iostream>
  2. #include <map>
  3. #include <vector>
  4. #include <string>
  5. #include <algorithm>
  6. using namespace std;
  7.  
  8. int main()
  9. {
  10. map<string,vector<int>> countriesAndYears;
  11.  
  12. int n;
  13. string country;
  14. int year,visit;
  15. cin >> n;
  16. for(int i=0;i<n;++i)
  17. {
  18. cin >> country >> year;
  19. countriesAndYears[country].push_back(year);
  20. }
  21. for (const auto& elem : countriesAndYears)
  22. {
  23. sort(elem.begin(),elem.end());
  24. }
  25. cin >> n;
  26. for(int i=0;i<n;++i)
  27. {
  28. cin >> country >> visit;
  29. cout << countriesAndYears[country][visit-1] << "\n";
  30. }
  31. return 0;
  32. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
4
Iceland 2014
Iceland 2015
Iceland 2015
Iceland 2016
4
Iceland 4
Iceland 3
Iceland 2
Iceland 1
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:23:13: error: ‘const struct std::pair<const std::__cxx11::basic_string<char>, std::vector<int> >’ has no member named ‘begin’
   sort(elem.begin(),elem.end());
             ^~~~~
prog.cpp:23:26: error: ‘const struct std::pair<const std::__cxx11::basic_string<char>, std::vector<int> >’ has no member named ‘end’; did you mean ‘second’?
   sort(elem.begin(),elem.end());
                          ^~~
stdout

Standard output is empty