字符统计1 (sdut oj)

    xiaoxiao2021-03-26  33

    字符统计1

    Time Limit: 1000MS  Memory Limit: 65536KB

    Problem Description

    给出一串字符,要求统计出里面的字母、数字、空格以及其他字符的个数。 字母:A, B, ..., Z、a, b, ..., z组成 数字:0, 1, ..., 9  空格:" "(不包括引号)  剩下的可打印字符全为其他字符。

    Input

    测试数据有多组。 每组数据为一行(长度不超过100000)。 数据至文件结束(EOF)为止。

    Output

    每组输入对应一行输出。 包括四个整数a b c d,分别代表字母、数字、空格和其他字符的个数。

    Example Input

    A0 ,

    Example Output

    1 1 1 1

    Hint

     

    Author

    ZJGSU

    参考代码

    #include<stdio.h> #include<string.h> int main() { char s[100001]; int i,n; int a,b,c,d; while(gets(s) != NULL) { n = strlen(s); a = 0; b = 0; c = 0; d = 0; for(i = 0; i < n; i++) { if((s[i] >= 'a' && s[i] <= 'z') || (s[i] >= 'A' && s[i] <= 'Z')) { a++; } else if(s[i] >= 48 && s[i] <= 57) { b++; } else if(s[i] == ' ') { c++; } else { d++; } } printf("%d %d %d %d",a,b,c,d); printf("\n"); } return 0; }

    字符统计1

    Time Limit: 1000MS  Memory Limit: 65536KB Submit  Statistic

    Problem Description

    给出一串字符,要求统计出里面的字母、数字、空格以及其他字符的个数。 字母:A, B, ..., Z、a, b, ..., z组成 数字:0, 1, ..., 9  空格:" "(不包括引号)  剩下的可打印字符全为其他字符。

    Input

    测试数据有多组。 每组数据为一行(长度不超过100000)。 数据至文件结束(EOF)为止。

    Output

    每组输入对应一行输出。 包括四个整数a b c d,分别代表字母、数字、空格和其他字符的个数。

    Example Input

    A0 ,

    Example Output

    1 1 1 1

    Hint

     

    Author

    ZJGSU
    转载请注明原文地址: https://ju.6miu.com/read-650168.html

    最新回复(0)