参考#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define LINE 100
#define CHARNUM 1000
void printAlpha(char *str);
int main(void)
{
char *sArr[LINE] = {NULL};
char *s = NULL;
char ch;
int i = 0, j = 0;
// 获取输入 ! 表示结束
while ( (ch=getchar()) != '!' )
{
s = (char *) malloc( sizeof(char) * CHARNUM );
memset(s, '\0', sizeof(char) * CHARNUM);
i = 0;
while( (ch=getchar()) != '\n' )
{
s[i++] = ch;
}
sArr[j++] = s;
}
// 打印输出
i = 0;
while( (s=sArr[i++]) != NULL)
{
printAlpha(s);
}
return 0;
}
void printAlpha(char *str)
{
int i = 0, j, max;
int sArr[26] = {0};
char s;
// 统计
while( (s=str[i++]) != '\0' )
{
if ( (s>='A') && (s<='Z') )
{
// 大写
sArr[s - 65] += 1;
}
else if ( (s>='a') && (s<='z') )
{
// 小写
sArr[s - 97] += 1;
}
}
// 找出现次数最多的
max = 0;
j = 0;
for( i=0; i<26; i++)
{
if ( sArr[i]>max )
{
max = sArr[i];
j = i;
}
}
printf("%c = %d\n", 65+j, max);
}
|