1 solutions

  • 0
    @ 2025-3-3 16:27:12

    C :

    #include<stdio.h>
    #include<string.h>
    main()
    {
    	char ch[10000];
    	int i,num1,num2,num3,num4;
    	while(gets(ch)!=NULL)
    	{
    		for(i=0,num1=0,num2=0,num3=0,num4=0;i<strlen(ch);i++)
    		{
    			if(ch[i]>='A'&&ch[i]<='Z'||ch[i]>='a'&&ch[i]<='z')
    			num1++;//character
    			else if(ch[i]==' ')
    			num2++;//space
    			else if(ch[i]>='0'&&ch[i]<='9')
    			num3++;//number
    			else
    			num4++;//else
    		}
    		printf("%d %d %d %d\n",num1,num3,num2,num4);
    	}
    }
    

    C++ :

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

    Information

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