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
    评论
下面是使用 x86 汇编语言统计字符串英文字母个数的示例代码: ``` section .data str db 'Hello, World!',0 len equ $-str section .text global _start _start: mov ecx, len ; 将字符串长度存储在 ecx mov esi, str ; 将字符串地址存储在 esi xor eax, eax ; 将 eax 清零 xor ebx, ebx ; 将 ebx 清零 count_loop: cmp ecx, 0 ; 判断是否到字符串结尾 je count_done mov al, [esi] ; 将当前字符存储在 al cmp al, 'A' ; 比较字符是否大于等于 'A' jb count_next cmp al, 'Z' ; 比较字符是否小于等于 'Z' ja count_lower inc ebx ; 增加大写字母计数器 jmp count_next count_lower: cmp al, 'a' ; 比较字符是否大于等于 'a' jb count_next cmp al, 'z' ; 比较字符是否小于等于 'z' ja count_next inc ebx ; 增加小写字母计数器 count_next: inc esi ; 增加字符串指针 dec ecx ; 减少字符串长度 jmp count_loop count_done: ; 计数结果存储在 ebx ; 可以进行打印或其他操作 mov eax, 1 ; 调用系统调用 1 (write) mov ebx, 1 ; 将文件描述符存储在 ebx mov ecx, ebx ; 将计数器值存储在 ecx int 0x80 ; 调用系统调用 mov eax, 0 ; 调用系统调用 0 (exit) xor ebx, ebx ; 将返回值存储在 ebx int 0x80 ; 调用系统调用 ``` 该代码将字符串存储在 `.data` 段的 `str` 变量,并将字符串长度存储在 `len` 。`count_loop` 标签处的代码循环遍历字符串的每个字符,并根据字符是否为英文字母来增加计数器。最后,计数结果存储在 `ebx` ,可以进行打印或其他操作。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值