sahadat49

Multimap

Sep 28th, 2019
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int n;
  6. map<char,int>mp;
  7. map<char,int> :: iterator it;
  8. cin>>n;
  9. cin.ignore();
  10. string s,s1="";
  11. while(n--){
  12. getline(cin,s);
  13. for(int i=0 ; i<s.size() ; i++){
  14. if(isalpha(s[i])){
  15. s1+=toupper(s[i]);
  16. }
  17. }
  18. }
  19. for(int i=0 ; i<s1.size() ; i++){
  20. mp[s1[i]]++;
  21. }
  22. multimap<int, char, greater <int> > mp2;
  23. multimap<int, char, greater <int> > :: const_iterator it1;
  24. for(it=mp.begin() ; it!=mp.end() ; it++){
  25. mp2.insert(make_pair(it->second , it->first));
  26. }
  27.  
  28. for(it1=mp2.begin() ; it1!=mp2.end() ; it1++){
  29. cout<<it1->second <<" " <<it1->first <<endl;
  30. }
  31. return 0;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment