程序填空题: 最多的字母
输入一个由小写英文字母构成的字符串,统计出现次数最多的字母及其出现次数并输出。请填空完成相应程序功能。
```
#include
#define N 80
int main(void)
{char str[N];
int count[26]={0},i=0,max_n,max_i;
@@[gets(str)](2); //输入字符串
while(@@[str[i]!='\0'](2)) //统计字符个数
{count[str[i]-'a']++;
i++;
}
max_n=count[0];
@@[max_i=0](2);
for(i=1;@@[i<=25](2);i++) //找出现次数最多的字母
{if(@@[count[i]>max_n](2))
{max_n=count[i];
max_i=i;
}
}
printf("%c,%d\n",'a'+max_i,max_n);
return 0;
}
```
答案:
第1空:gets(str)
第2空:str[i]!='\0'
第3空:max_i=0
第4空:i<=25
第5空:count[i]>max_n
```
#include
#define N 80
int main(void)
{char str[N];
int count[26]={0},i=0,max_n,max_i;
@@[gets(str)](2); //输入字符串
while(@@[str[i]!='\0'](2)) //统计字符个数
{count[str[i]-'a']++;
i++;
}
max_n=count[0];
@@[max_i=0](2);
for(i=1;@@[i<=25](2);i++) //找出现次数最多的字母
{if(@@[count[i]>max_n](2))
{max_n=count[i];
max_i=i;
}
}
printf("%c,%d\n",'a'+max_i,max_n);
return 0;
}
```
答案:
第1空:gets(str)
第2空:str[i]!='\0'
第3空:max_i=0
第4空:i<=25
第5空:count[i]>max_n