Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <utility>
- #include <string>
- #include <algorithm>
- using namespace std;
- bool cmp(const pair <char, int> &a, const pair <char, int> &b) {
- if (a.second == b.second)
- return a.first < b.first;
- return a.second > b.second;
- }
- int main() {
- string S;
- cin >> S;
- vector <pair <char, int>> LC(1);
- LC[0].first = S[0];
- LC[0].second = 1;
- pair <char, int> lc_pair;
- bool new_char = true;
- for (int i = 1; i < S.length(); i++) {
- new_char = true;
- for (int j = 0; j < LC.size(); j++) {
- if (S[i] == LC[j].first) {
- LC[j].second++;
- new_char = false;
- }
- }
- if (new_char) {
- lc_pair.first = S[i];
- lc_pair.second = 1;
- LC.push_back(lc_pair);
- }
- }
- sort(&LC[0], &LC[LC.size()], cmp);
- for (auto lc : LC) {
- cout << lc.first << ' ' << lc.second << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment