1 solutions

  • 0
    @ 2025-11-5 19:23:17

    C :

    #include<stdio.h>
    #include<ctype.h>
    int main()
    {
        char a[1000];
        int i=-1;
        int zm,kg,sz,others;
        zm=kg=sz=others=0;
        gets(a);
        while(a[++i]!='\0')
        {
            if(isalpha(a[i])) zm++;
            else if(isdigit(a[i])) sz++;
            else if(isblank(a[i])) kg++;
            else others++;
        }
        printf("%d %d %d %d\n",zm,sz,kg,others);
        return 0;
    }
    
    

    C++ :

    #include<stdio.h>
    int main()
    {
        int a,b,c,d,e;
        char k[100],*p;
        a=b=c=d=e=0;
        gets(k);
        p=k;
        while(*p)
        {
            if(*p>='a'&&*p<='z'||*p>='A'&&*p<='Z')
                a++;
            else if(*p==' ')
                b++;
            else if(*p>='0'&&*p<='9')
                c++;
            else d++;
            p++;
        }
        printf("%d %d %d %d\n",a,c,b,d);
        return 0;
    }
    
    
    • 1

    C语言程序设计教程(第三版)课后习题6.2

    Information

    ID
    19322
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By