1 条题解

  • 0
    @ 2025-4-14 18:41:37

    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)

    信息

    ID
    3103
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者