Created
July 18, 2017 00:58
-
-
Save jason790228/26e57a447d3a3336c2e536ef030a7245 to your computer and use it in GitHub Desktop.
10008
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <map> | |
#include <vector> | |
#include <iostream> | |
#include <algorithm> | |
#include <sstream> | |
#include <ctype.h> | |
using namespace std; | |
void run(map<char, int>& input, string s) | |
{ | |
for (char c : s) | |
{ | |
if (isalpha(c)) | |
{ | |
input[toupper(c)]++; | |
} | |
} | |
} | |
void output(const map<char, int>& output) | |
{ | |
struct CmpByValue { | |
inline bool operator()(const pair<char, int> & lhs, const pair<char, int> & rhs) | |
{ | |
return lhs.second > rhs.second; | |
} | |
}; | |
vector<pair<char, int>> counts(output.begin(), output.end()); | |
sort(counts.begin(), counts.end(), CmpByValue()); | |
for (int i = 0; i != counts.size(); ++i) | |
{ | |
cout << counts[i].first << " " << counts[i].second << endl; | |
} | |
} | |
int main() | |
{ | |
map<char, int> temp; | |
int a; | |
cin >> a; | |
cin.ignore(1, '\n'); | |
for (int i = 0; i < a; i++) | |
{ | |
string s; | |
getline(cin, s); | |
run(temp, s); | |
} | |
output(temp); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment