1 条题解

  • 0
    @ 2025-2-14 20:50:07

    C :

    #include <stdio.h>
    #include <stdlib.h>
    int main()
    {
       int i,j,word=0,num=0,space=0,other=0;   
       char text[3][80]={'\0'};   
       char c;   
       for(i=0;i<=2;i++)           
    	   gets(text[i]);  
       for(i=0;i<=2;i++)  
       {     int word=0,num=0,space=0,other=0;    
    	   for(j=0;j<80;j++)       
    	   {    
    		   if((c=text[i][j])=='\0')     
    			   break;                          
    		   if(c>='A'&&c<='Z') word++;
    		   else if(c>='a'&&c<='z') word++;    
    		   else if(c>='0'&&c<'9') num++;               
    		   else if(c==' ') space++;                
    		   else other++; 
    	   }   
    	    printf("%d %d %d %d\n",word,num,space,other);
       }
    }
    

    C++ :

    #include <stdio.h>
    int main()
    {
       int upper,lower,digit,space,other,i,j;
       char a[3][80];
       gets(a[0]);
       gets(a[1]);
       gets(a[2]);
       for(i=0;i<3;i++)
       {
           upper=0;lower=0;digit=0;space=0;other=0;
           for(j=0;a[i][j]!='\0';j++)
    	   {
    
                  if(a[i][j]>='a'&&a[i][j]<='z')
                  lower++;
                   else if(a[i][j]>='A'&&a[i][j]<='Z')
                             upper++;
                          else if(a[i][j]>='0'&&a[i][j]<='9')
                                        digit++;
                                else if(a[i][j]==' ')
                                        space++;
    							else
                                         other++;
    							}
    		
                  
                      printf("%d %d %d %d\n",lower+upper,digit,space,other);
    	   
                    
    	}
    }
       
     
    
    
    
    

    Pascal :

    program xzy1;
      var
        a,b,c:string;
        o,p,q,r,i:integer;
      begin
        readln(a);
        readln(b);
        readln(c);
        o:=0;
        p:=0;
        q:=0;
        r:=0;
        for i:= 1 to length(a) do
          case a[i] of
            'a'..'z':o:=o+1;
            'A'..'Z':o:=o+1;
            '0'..'9':p:=p+1;
            ' ':q:=q+1;
            else r:=r+1;
          end;
        writeln(o,' ',p,' ',q,' ',r);
        o:=0;
        p:=0;
        q:=0;
        r:=0;
        for i:= 1 to length(b) do
          case b[i] of
            'a'..'z':o:=o+1;
            'A'..'Z':o:=o+1;
            '0'..'9':p:=p+1;
            ' ':q:=q+1;
            else r:=r+1;
          end;
        writeln(o,' ',p,' ',q,' ',r);
        o:=0;
        p:=0;
        q:=0;
        r:=0;
        for i:= 1 to length(c) do
          case c[i] of
            'a'..'z':o:=o+1;
            'A'..'Z':o:=o+1;
            '0'..'9':p:=p+1;
            ' ':q:=q+1;
            else r:=r+1;
          end;
        writeln(o,' ',p,' ',q,' ',r);
      end.
    
    • 1

    信息

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