In this problem we are interested in the frequency of letters in a given line of text. Specifi-cally, we want to know the most
frequently occurring letter(s) in the text, ignoring case (to be clear, “letters” refers precisely to the 26 letters of the alphabet).
Input
Input begins with the number of test cases on its own line. Each test case consists of a single line of text. The line may contain non-letter characters, but is guaranteed to contain at least one letter and less than 200 characters in total.
Output
For each test case, output a line containing the most frequently occurring letter(s) from the text in lowercase (if there are ties, output all such letters in alphabetical order).
Sample Input
1
Computers account for only 5% of the country’s commercial electricity consumption.
Sample Output
co
问题链接:UVA11577 Letter Frequency
问题简述:(略)
问题分析:
统计输入的每一行中各个字母的数量,按字母顺序输出出现频率最高的字母。
简单的统计题,不解释。
程序说明:(略)
参考链接:(略)
题记:(略)
AC的C++语言程序如下:
/* UVA11577 Letter Frequency */
#include <bits/stdc++.h>
using namespace std;
const int AN = 26;
const int N = 200;
char s[N + 1];
int cnt[AN];
int main()
{
int n;
scanf("%d", &n);
getchar();
while(n--) {
gets(s);
memset(cnt, 0, sizeof(cnt));
for(int i = 0; s[i]; i++) {
if(islower(s[i]))
cnt[s[i] - 'a']++;
else if(isupper(s[i]))
cnt[s[i] - 'A']++;
}
int maxf = -1;
for(int i = 0; i < AN; i++)
maxf = max(maxf, cnt[i]);
for(int i = 0; i < AN; i++)
if(cnt[i] == maxf)
putchar('a' + i);
putchar('\n');
}
return 0;
}