#include<iostream> #include<map> using namespace std; int main(int argc, char *argv[]) { // key is a word (string), data is a count (int) map<string, int> bst; map<string,int>::iterator it; // read input, insert words into bst string s; while (cin >> s) { it = bst.find(s); if (it == bst.end()) { // could have done this instead - //if (bst.count(s) == 0) // insert word s into the bst with count of 1 bst.insert(pair<string, int>(s, 1)); } else { it->second ++ ; // could have done this instead - //bst.at(s) ++; } } // print the bst for (it=bst.begin(); it!=bst.end(); ++it) { cout << it->first << " => " << it->second << '\n'; } return 0; }