fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <map>
  4. using namespace std;
  5.  
  6. int main() {
  7. map<string, int> letter;
  8. string word;
  9. while (cin >> word)
  10. letter[word]++;
  11. for (map<string, int>::iterator it = letter.begin(); it != letter.end(); it++)
  12. cout << "map[\"" << it->first << "\"] = " << it->second << endl;
  13. return 0;
  14. }
  15.  
Success #stdin #stdout 0.02s 2864KB
stdin
test test
a b c d
d e f g
stdout
map["a"] = 1
map["b"] = 1
map["c"] = 1
map["d"] = 2
map["e"] = 1
map["f"] = 1
map["g"] = 1
map["test"] = 2