1042. Character statistics (20)
Please write the program to find the most frequent English letters in a given text.
Input format:
Input a string with a length of no more than 1000 in one line. The string is composed of any visible characters and spaces in the ASCII code, which contains at least one English letter, which ends at the end of the car (the car is not included).
output format:
The English letters with the highest frequency of output and the number of times appeared in one line, and separated by spaces. If there is side by side, the letter with the smallest letter order is output. Statistically do not distinguish between lower and lowercase and output lowercase letters.
Input Sample example:
This is a simple TEST. There ARE numbers and other symbols 1&2&3...........
output sample:
e 7
Thought: and
[The Beauty of Programming -02] String contains problems
The
Efficient solution method is done according to the principle of the ASCII code, but it is not considered here, so the size of the array is 27. Note: You have to read the input with gets (). Because you need to read it all.
#include<stdio.h>
#include<string.h>
char s[1002];
int main()
{
//freopen("E://input.txt", "r", stdin);
while(gets(s))
{
int count[27];
memset(count, 0, sizeof(count));
for(int i = 0; i < strlen(s); i ++)
{
if(s[i] >= 'A' && s[i] <= 'Z')
count[s[i]-'A'] ++;
if(s[i] >= 'a' && s[i] <= 'z')
count[s[i]-'a'] ++;
}
int max = 0, index = 0;
for(int i = 0; i < 27; i ++)
{
if(count[i] > max)
{
max = count[i];
index = i;
}
}
printf("%c %d\n", index+'a', max);
}
return 0;
}