题解 | #字母统计#

字母统计

https://www.nowcoder.com/practice/de7bf0945c1c4bd1aa9d49573b831f3c

#include <stdio.h>
#include <string.h>

int main() {
    char str[100];
    while (scanf("%s", str) != EOF) {
        int a[26] = {0};
        int length = strlen(str);
        for (int i = 0; i < length; i++) {
            // scanf("%c",&str[i]);
            //在循环读取字符串中字符的时候,不需要使用scanf()
            //因为已经通过scanf("%s", str)读取了整个字符串
            if (str[i] >= 'A' && str[i] <= 'Z') {
                a[str[i] - 'A']++;
            }
        }
        for (int i = 0; i < 26; i++) {
            printf("%c:%d\n", 'A' + i, a[i]);
        }
    }
    return 0;
}

全部评论

相关推荐

陌夏微秋:一线城市25w左右吧,17×15=255
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务