1 条题解

  • 0
    @ 2025-4-7 21:29:59

    C :

    #include<stdio.h>
    int main()
    {	
    	char ch;
    	int letter=1,i,blank=0,number=0,others=0; 
    	scanf("%c",&ch); 
    	while((ch=getchar())!= '\n') 
    	{		
    		if('a'<=ch && ch<='z' || 'A'<=ch && ch<='Z') 
    		{			
    			letter++;	
    		}		
    		else if('0'<=ch&&ch<='9')	
    		{		
    			number++;	
    		}		
    		else if(ch==' ')	
    		{			
    			blank++;
    		}		else	
    		{			
    			others++;	
    		}	
    	}	
    	printf("characters=%d\n",letter);
    	printf("spaces=%d\n",blank);
    	printf("numbers=%d\n",number);
    	printf("others=%d\n",others);
    	return 0;
    }
    

    C++ :

    #include<stdio.h>
    #include<stdlib.h>
    #include<string.h> 
    int i,a[4];
    char t;
    int main()      
    {        
       for(i=0;;i++) 
       {
       scanf("%c",&t);
       if(t=='\n')break;
       else if(t>='A'&&t<='Z') a[0]++;
            else if(t>='a'&&t<='z')a[0]++;
                 else if(t==' ')a[1]++;  
                      else if(t>='0'&&t<='9')a[2]++;
                           else a[3]++;
                    
       }
       
       printf("characters=%d\n",a[0]);
      printf("spaces=%d\n",a[1]);
      printf("numbers=%d\n",a[2]);
      printf("others=%d\n",a[3]);
    }
    
    • 1

    信息

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