fork download
  1. #include <map>
  2. #include <cstdio>
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. typedef map<std::string, int> wc;
  7. void printmap(const wc& m) {
  8. for(wc::const_iterator i=m.begin(); i!=m.end(); ++i)
  9. std::cout << i->first << "->" << i->second << '\n';
  10. }
  11.  
  12. int main() {
  13. int c;
  14. string cc, nombre;
  15. wc m;
  16. std::cin >> c;
  17. while (c--) {
  18. std::cin >> cc;
  19. std::getline(std::cin, nombre);
  20. ++m[cc]; // This should work
  21. }
  22. printmap(m);
  23. }
Success #stdin #stdout 0.01s 2820KB
stdin
3
Spain Donna Elvira
England Jane Doe
Spain Donna Anna
stdout
England->1
Spain->2