题解 | #字符个数统计#

字符个数统计

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

#include <stdio.h>

int main() {
    char a[500]="";
    int arr[128]={0};
    int count=0;
    while (scanf("%s", a) != EOF) { // 注意 while 处理多个 case
        //获取字符串以后
        //遍历整个字符串判断,如果计算过,则在arr中对应下标写1
        char *q=a;
        while (*q) {
            int num=(int)*q;
            if(arr[num]==0)//表示该字符未计算过
            {
                count++;
                arr[num]=1;//改变标志
            }
            q++;
        }
        printf("%d\n",count);
    }
    return 0;
}

全部评论

相关推荐

昨天 14:37
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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