fork download
  1. #include <iostream>
  2. #include <sstream>
  3. #include <string>
  4. #include <map>
  5. #include <vector>
  6.  
  7. using namespace std;
  8.  
  9. typedef map<string, int> simap;
  10.  
  11. typedef pair<simap::key_type, simap::mapped_type> si_element;
  12.  
  13. typedef vector<si_element> sivec;
  14.  
  15. int main()
  16. {
  17. int num;
  18. cin >> num;
  19. simap letter;
  20. string line, word;
  21.  
  22. for(int i = 0; i < num; ++i)
  23. {
  24. do{
  25. getline(cin, line);
  26. }while(line.empty()); // In case there are empty lines.
  27.  
  28. istringstream stream(line);
  29. while (stream >> word)
  30. {
  31. letter[word]++;
  32. }
  33. }
  34.  
  35. sivec vecofmap(letter.begin(), letter.end());
  36.  
  37. for(sivec::const_iterator it(vecofmap.begin()); it != vecofmap.end(); ++it)
  38. {
  39. cout << "vecofmap[\"" << it->first << "\"] = " << it->second << endl;
  40. }
  41.  
  42. return 0;
  43. }
Success #stdin #stdout 0.01s 2868KB
stdin
3
Hello world!
enter your input (stdin)
enter your note
stdout
vecofmap["(stdin)"] = 1
vecofmap["Hello"] = 1
vecofmap["enter"] = 2
vecofmap["input"] = 1
vecofmap["note"] = 1
vecofmap["world!"] = 1
vecofmap["your"] = 2