1 solutions

  • 0
    @ 2025-11-5 16:11:58

    C :

    #include<stdio.h>
    #include<stdlib.h>
    int main(void){
        char c;
        int num1=0,num2=0,num3=0,num4=0;
        c=getchar();
        while(c!='\n'){
            if(('a'<=c&&c<='z')||('A'<=c&&c<='Z')){
                num1++;}
            else if('0'<=c&&c<='9'){
                num2++;}
            else if(c==' '){
                num3++;}
            else{
                num4++;}
        c=getchar();
        }
        printf("%d %d %d %d\n",num1,num2,num3,num4);
        return 0;
    }
    

    C++ :

    #include<iostream>
    #include<string>
    #include<cctype>
    using namespace std;
    int main()
    {
    	string s;
    	getline(cin,s);
    	int len=s.size();
    	int letter=0,space=0,digit=0,other=0;
    	for (int i=0; i<len; i++)
    		if (isalpha(s[i])) letter++;
    		else if (s[i]==' ') space++;
    		else if (isdigit(s[i])) digit++;
    		else other++;
    	cout<<letter<<" "<<digit<<" "<<space<<" "<<other<<endl;
    	return 0;
    }
    
    • 1

    2002年秋浙江省计算机等级考试二级C 编程题(1)

    Information

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