fork download
  1. #include <iostream>
  2. #include <string>
  3. #include <unordered_map>
  4. #include <utility>
  5.  
  6. using namespace std;
  7.  
  8. int main () {
  9. unordered_map<string, size_t> cnt;
  10. bool flag = true;
  11. string tmp;
  12. char c;
  13. while(flag) {
  14. if(!(cin>>c)) break;
  15. switch(c) {
  16. case '.': flag = false;
  17. case ',': cnt[tmp] ++; tmp = ""; break;
  18. default: tmp+=c; break;
  19. }
  20. }
  21. for(auto& it: cnt) {
  22. cout << it.first << ' ' << it.second << endl;
  23. }
  24. return 0;
  25. }
Success #stdin #stdout 0s 3436KB
stdin
ab,ab,ba,ba,ccc,ccc,asdf.
stdout
asdf 1
ccc 2
ba 2
ab 2