样例对了啊!
#include <iostream>
#include <cctype>
#include <cstdio>
#include <algorithm>
#include <string>
using namespace std;
class Node
{
public:
int f, x;
Node();
};
Node::Node()
{
x = 0;
}
inline bool cmp(const Node& x, const Node& y)
{
return (x.f == y.f ? x.f < y.f : x.x > y.x);
}
Node a[30];
int main()
{
ios::sync_with_stdio(false);
int n, cur = 0;
cin >> n;
getchar();
for (register int i = 1; i <= n; i++)
{
string s;
getline(cin, s);
transform(s.begin(), s.end(), s.begin(), ::toupper);
int len = s.length() - 1;
for (register int j = 0; j <= len; j++)
{
if (isalpha(s[j]))
{
a[s[j] - 'A' + 1].x++;
a[s[j] - 'A' + 1].f = s[j];
}
}
}
sort(a + 1, a + 30, cmp);
for (register int i = 1; i <= 26; i++)
{
if (a[i].x == 0)
{
continue;
}
else
{
cout << char(a[i].f) << " " << a[i].x << endl;
}
}
system("pause");
return 0;
}