Advertisement
Guest User

Untitled

a guest
Jun 24th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <string>
  4. #include <algorithm>
  5.  
  6. #define endl '\n'
  7.  
  8. using namespace std;
  9.  
  10. char c;
  11.  
  12. bool isFirstElement(const pair<char,int> &element){
  13. return element.first == c;
  14. }
  15.  
  16. bool sortBySec(const pair<int,int> &a, const pair<int,int> &b)
  17. {
  18. if(a.second < b.second)
  19. return (a.second < b.second);
  20. return a.first > b.first;
  21. }
  22.  
  23. int main(){
  24. string str;
  25. while(cin >> str){
  26. vector< pair<char,int> > vect;
  27.  
  28. for(int i=0;i < str.length(); i++ ){
  29. c = str[i];
  30. vector< pair<char,int> > :: iterator it ;
  31. it = find_if(vect.begin(), vect.end(), isFirstElement);
  32. if (it == vect.end()){
  33. vect.push_back( make_pair(c,1) );
  34. }
  35. else{
  36. it->second++;
  37. }
  38. }
  39.  
  40. sort(vect.begin(), vect.end(), sortBySec);
  41.  
  42. for (int i = 0; i < vect.size(); i++)
  43. cout << int(vect[i].first) << ' ' << vect[i].second << endl;
  44. cout << endl;
  45. }
  46.  
  47.  
  48. return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement