Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <map>
- #include <string>
- #include <vector>
- #include <algorithm>
- using namespace std;
- bool compare (pair<int, string> a, pair<int, string> b)
- {
- if (a.first != b.first) {
- return (a.first > b.first);
- } else {
- return lexicographical_compare(a.second.begin(), a.second.end(), b.second.begin(), b.second.end());
- }
- }
- int main()
- {
- string z;
- map<string, int> array;
- while(cin >> z){
- if(array.count(z) == 0){
- array[z] = 1;
- }
- else{
- array[z]++;
- }
- }
- //for (auto el: array) {
- // cout << el.first << " " << el.second << endl;
- //}
- vector<pair<int,string>> a;
- for(auto el: array){
- pair<int, string> tmp;
- tmp.first = el.second;
- tmp.second = el.first;
- a.push_back(tmp);
- }
- //for (auto el: a) {
- // cout << el.second << " " << el.first << endl;
- //}
- sort(a.begin(), a.end(), compare);
- for(auto el: a){
- cout << el.second << endl;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement