文章

70

粉丝

0

获赞

272

访问

48.9k

头像
字母统计 题解:C语言数组计数器
P1292 上海交通大学机试题
发布于 2026年3月
阅读数 899

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

int main(){
    int count[26];  //count[0]表示‘A’出现的次数
    char s[1000];
    char a[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};

    while( scanf("%s",s)!=EOF ){
        for(int i=0; i<26; i++) count[i]=0;  //初始化计数器为全0
        int i=0;
        while( s[i++] ){
            if( 'A'<=s[i-1] && s[i-1]<='Z' ) count[s[i-1]-'A']++; 
        }
    ...

登录查看完整内容


登录后发布评论

暂无评论,来抢沙发