以ä¸æ¯ç»è®¡26个è±æå°ååæ¯åºç°ç次æ°
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void Stat(char *str,int count[])
{
int i;
for(i=0;i<26;i++)count[i]=0;
for(i=0;i<strlen(str);i++)
{
if(str[i]=='a')count[0]++;
else if(str[i]=='b')count[1]++;
else if(str[i]=='c')count[2]++;
else if(str[i]=='d')count[3]++;
else if(str[i]=='e')count[4]++;
else if(str[i]=='f')count[5]++;
else if(str[i]=='g')count[6]++;
else if(str[i]=='h')count[7]++;
else if(str[i]=='i')count[8]++;
else if(str[i]=='j')count[9]++;
else if(str[i]=='k')count[10]++;
else if(str[i]=='l')count[11]++;
else if(str[i]=='m')count[12]++;
else if(str[i]=='n')count[13]++;
else if(str[i]=='o')count[14]++;
else if(str[i]=='p')count[15]++;
else if(str[i]=='q')count[16]++;
else if(str[i]=='r')count[17]++;
else if(str[i]=='s')count[18]++;
else if(str[i]=='t')count[19]++;
else if(str[i]=='u')count[20]++;
else if(str[i]=='v')count[21]++;
else if(str[i]=='w')count[22]++;
else if(str[i]=='x')count[23]++;
else if(str[i]=='y')count[24]++;
else if(str[i]=='z')count[25]++;
}
}
int main(void)
{
char str[10000];
int i,count[26];
printf("请è¾å
¥a~zçå符串:\n");
gets(str);
Stat(str,count);
for(i=0;i<26;i++)
printf("%c:%d\n",i+'a',count[i]);
system("pause");
return 0;
}
ç¥ä½ æå¿«ï¼
温馨提示:答案为网友推荐,仅供参考