7-11 统计字符串中各个小写英文字母的个数

从键盘输入一行字符,统计出其中每个小写英文字母的个数,最后按照从az的顺序输出它们的个数。

说明:编写程序时可以使用string.h中的函数strlen().

输入格式:

在一行输入长度不超过1000的一个字符串。

输出格式:

最后按照从az的顺序输出每个字母的个数,每个数字之间用空格间隔。数字序列的首尾不能有空格

输入样例:

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;
}

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值