1 solutions

  • 0
    @ 2025-11-5 16:13:48

    C :

    #include <stdio.h>
    #include <math.h>
    #include <string.h>
    #include <ctype.h>
    
    int main()
    {
    	char a[81];
    	gets(a);
    	int i=0,j=0,k=0,l=0,n;
    	for (n=0;a[n]!='\0';n++)
    	{
    		if (isalpha(a[n]))
    			i++;
    		else 
    			if (a[n]==' ')
    			j++;
    		else 
    			if (isdigit(a[n]))
    			k++;
    		else
    			l++;
    	}
    	printf ("%d\n%d\n%d\n%d\n",i,j,k,l);
    	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<<endl<<space<<endl
    		<<digit<<endl<<other<<endl;
    	return 0;
    }
    
    • 1

    Information

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