Description
费了好长时间敲出的一篇论文,想不想知道其中敲了多少个字母?那么现在我们去写一个程序实现吧!
Input
输入有多行数据,每行数据不会超过10000个字符,同时我们保证,每行不会出现空格和TAB。
Output
对于每一行输入数据,按出现次数从大到小输出该字母和出现的次数,字母统一用大写字母表示,如果两个字母出现次数相同,按字母表的先后顺序输出,如果这个字母没有出现,不输出该字母。输出完该行所有字母的出现次数后,输出“—”。
Sample Input
Congqianyouzuoshan,
Shanshangyougemiao,
Miaomiaomiao~~
Sample Output
N 3
O 3
A 2
U 2
C 1
G 1
H 1
I 1
Q 1
S 1
Y 1
Z 1
A 3
G 2
H 2
N 2
O 2
S 2
E 1
I 1
M 1
U 1
Y 1
A 3
I 3
M 3
O 3
#include<stdio.h>
#include<iostream>
#include<map>
#include<algorithm>
#include<cstring>
#include<string.h>
#include<string>
#include<math.h>
#include<vector>
#include<map>
using namespace std;
typedef long long ll;
#define MAXN 10005
#define INF 0x3f3f3f3f//将近int类型最大数的一半,而且乘2不会爆int
const ll MOD = 332748118;
struct student
{
char ch;
int ans;
}stu[30];
void init()
{
for(int i=1; i<=26; ++i)
{
stu[i].ch = i+64;
stu[i].ans = 0;
}
}
int cmp(student x, student y)
{
if(x.ans != y.ans)
return x.ans > y.ans;
return x.ch < y.ch;
}
int main()
{
char sh[MAXN];
while(scanf("%s", sh)!=EOF)
{
init();
int len = strlen(sh);
for(int i=0; i<len; ++i)
{
if(sh[i] >= 'a' && sh[i] <= 'z')
stu[sh[i]-96].ans++;
if(sh[i] >= 'A' && sh[i] <= 'Z')
stu[sh[i]-64].ans++;
}
sort(stu+1, stu+27, cmp);
for(int i=1; i<=26; ++i)
{
if(stu[i].ans != 0)
cout << stu[i].ch << ' ' << stu[i].ans << '\n';
}
cout << "---" << '\n';
}
return 0;
}