Skip to content

Instantly share code, notes, and snippets.

@jason790228
Created July 18, 2017 00:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jason790228/26e57a447d3a3336c2e536ef030a7245 to your computer and use it in GitHub Desktop.
Save jason790228/26e57a447d3a3336c2e536ef030a7245 to your computer and use it in GitHub Desktop.
10008
#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