题目:
编写程序,接收用户从键盘输入的仅由小写字母构成的字符串(如:fhdekjreiwrerhfds),假设该字符串的最大长度为100,
统计并输出每个字母(’a’~’z’)的重复次数。
#include<stdio.h>
#include<stdlib.h>
int main()
{
char char_str[100] = { 0 };
int repeat[26] = { 0 };
int i;
scanf("%s", char_str);
for (i = 0; i < sizeof(char_str); i++)
repeat[char_str[i] - 'a']++;//哈希思想的体现
for (i = 0; i < 26; i++)
printf("%c\t%d\t\n", 'a'+i, repeat[i]);
system("pause");
return 0;
}