C语言OJ项目参考(1032) 统计字符个数

    xiaoxiao2026-02-17  17

    (1032) 统计字符个数 Description 输入一行字符,分别统计出其中英文字母、数字、空格和其他字符的个数。 Input 一行字符 Output 统计值 Sample Input aklsjflj123 sadf918u324 asdf91u32oasdf/.’;123 Sample Output 23 16 2 4

    [参考解答]

    #include "stdio.h" int main() { int alpha=0, number=0, space=0, others=0; //分别代表字母、数字、空格及其他字符个数 char ch; while ((ch=getchar())!='\n') { if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z')) alpha++; else if (ch>='0'&&ch<='9') number++; else if (ch==' ') space++; else others++; } printf("%d %d %d %d\n", alpha, number, space, others); return 0; } 相关资源:python入门教程(PDF版)
    最新回复(0)