从键盘输入一行字符,统计出其中每个小写英文字母的个数,最后按照从a
到z
的顺序输出它们的个数。
说明:编写程序时可以使用string.h
中的函数strlen()
.
输入格式:
在一行输入长度不超过1000的一个字符串。
输出格式:
最后按照从a
到z
的顺序输出每个字母的个数,每个数字之间用空格间隔。数字序列的首尾
不能有空格
。
输入样例:
The GNU General Public License is a free, copyleft license for software and other kinds of works.
输出样例:
4 1 4 2 12 5 0 2 5 0 2 4 0 5 6 1 0 6 6 3 1 0 2 0 1 0
代码长度限制
16 KB
时间限制
400 ms
内存限制
64 MB
#include <stdio.h>
int main()
{
int i,n;
char a[1001];
int b[26]={0};
gets(a);
n=strlen(a);
for(i=0;i<n;i++)
{
if(a[i]=='a') b[0]++;
else if(a[i]=='b') b[1]++;
else if(a[i]=='c') b[2]++;
else if(a[i]=='d') b[3]++;
else if(a[i]=='e') b[4]++;
else if(a[i]=='f') b[5]++;
else if(a[i]=='g') b[6]++;
else if(a[i]=='h') b[7]++;
else if(a[i]=='i') b[8]++;
else if(a[i]=='j') b[9]++;
else if(a[i]=='k') b[10]++;
else if(a[i]=='l') b[11]++;
else if(a[i]=='m') b[12]++;
else if(a[i]=='n') b[13]++;
else if(a[i]=='o') b[14]++;
else if(a[i]=='p') b[15]++;
else if(a[i]=='q') b[16]++;
else if(a[i]=='r') b[17]++;
else if(a[i]=='s') b[18]++;
else if(a[i]=='t') b[19]++;
else if(a[i]=='u') b[20]++;
else if(a[i]=='v') b[21]++;
else if(a[i]=='w') b[22]++;
else if(a[i]=='x') b[23]++;
else if(a[i]=='y') b[24]++;
else if(a[i]=='z') b[25]++;
}
for(i=0;i<26;i++)
{
if(i==25){
printf("%d ",b[i]);
break;
}
printf("%d ",b[i]);
}
return 0;
}