1 条题解

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

    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

    信息

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