Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- #include <algorithm>
- #define endl '\n'
- using namespace std;
- char c;
- bool isFirstElement(const pair<char,int> &element){
- return element.first == c;
- }
- bool sortBySec(const pair<int,int> &a, const pair<int,int> &b)
- {
- if(a.second < b.second)
- return (a.second < b.second);
- return a.first > b.first;
- }
- int main(){
- string str;
- while(cin >> str){
- vector< pair<char,int> > vect;
- for(int i=0;i < str.length(); i++ ){
- c = str[i];
- vector< pair<char,int> > :: iterator it ;
- it = find_if(vect.begin(), vect.end(), isFirstElement);
- if (it == vect.end()){
- vect.push_back( make_pair(c,1) );
- }
- else{
- it->second++;
- }
- }
- sort(vect.begin(), vect.end(), sortBySec);
- for (int i = 0; i < vect.size(); i++)
- cout << int(vect[i].first) << ' ' << vect[i].second << endl;
- cout << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement