fork(1) download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int n;
  6. cin >> n;
  7. string x;
  8. map <string , int > m;
  9. while(n--)
  10. {
  11. cin >> x;
  12. m[x]++;
  13. }
  14. map <string , int >::iterator it;
  15.  
  16. for(it = m.begin() ; it != m.end() ; it++)
  17. cout << it->first << " " << it->second << endl;
  18.  
  19. return 0;
  20. }
Success #stdin #stdout 0s 3280KB
stdin
7 
cse 
mnc 
cse 
ele 
cse 
zzza 
physics
stdout
cse 3
ele 1
mnc 1
physics 1
zzza 1