1 条题解

  • 0
    @ 2025-10-10 15:45:27

    C :

    #include<stdio.h>
    
    main()
    
    {
    
        char c;                                     /*定义c为字符型*/
    
        int letters = 0, space = 0, digit = 0;    /*定义letters、space、digit、others、四个变量为基本整型*/
        while ((c = getchar()) != '#')                      /*当输入的不是#时执行while循环体部分*/
        {
            if (c >= 'a' && c <= 'z')
    
                letters++;                              /*当输入的是英文字母时变量letters加1*/
    
            else
    
                if (c >= 'A' && c <= 'Z')
    
                    space++;                            /*当输入的是空格时变量space加1*/
    
            else
    
                if (c >= '0' && c <= '9')
    
                    digit++;                            /*当输入的是数字时变量digit加1*/
    
        }
    
        printf("%d %d %d",space,letters,digit);    /*将最终统计结果输出*/
    
    }
    
    

    C++ :

    #include<iostream>
    using namespace std;
    
    int main(){
    	
    	int a,b,c;
    	a=0;
    	b=0;
    	c=0;
    	
    	char x;
    
    	x=getchar();
    	while(x!='#'){
    		if(x>='A' && x<='Z')
    			a++;
    			
    		if(x>='a' && x<='z')
    			b++;
    			
    		if(x>='0' && x<='9')
    			c++;
    			
    		x=getchar();
    	}
    	cout<<a<<" "<<b<<" "<<c<<endl;
    	
    }
    
    

    Pascal :

    var
      st:string;
      d,x,s,i,l:longint;
    begin
      readln(st);
      l:=length(st);
      for i:=1 to l do
        if (ord(st[i])>=65) and (ord(st[i])<=90)
        then d:=d+1
        else if (ord(st[i])>=97) and (ord(st[i])<=122)
             then x:=x+1
             else if (ord(st[i])>=48) and (ord(st[i])<=57)
                  then s:=s+1
                  else if ord(st[i])=35
                       then break;
       writeln(d,' ',x,' ',s);
    end.
    

    Java :

    import java.util.Scanner;
    public class Main {
    	public static void main(String[] args) {
    		Scanner scanner =new Scanner(System.in);
    		String str=scanner.nextLine();
    		String[] strArray=str.split("#");
    		int dx=0;
    		int xx=0;
    		int sz=0;
    		if(strArray.length>0){
    			String s=strArray[0];
    			char[] charArray=s.toCharArray();
    			for(int i=0;i<charArray.length;i++){
    				int intc=charArray[i];
    				if(intc>=65&&intc<=90){
    					dx++;
    				}
    				if(intc>=97&&intc<=122){
    					xx++;
    				}
    				if(intc>=48&&intc<=57){
    					sz++;
    				}		
    			}
    			System.out.println(dx+" "+xx+" "+sz);
    		}		
    	}
    }
    

    Python :

    str = input('')
    a = 0
    b = 0
    c = 0
    for i in str:
        if i>='A' and i<='Z':
            a += 1
        if i>='a' and i<='z':
            b += 1
        if i>='0' and i<='9':
            c += 1
    print(a,b,c)    
    
    • 1

    信息

    ID
    92
    时间
    1000ms
    内存
    512MiB
    难度
    10
    标签
    递交数
    3
    已通过
    3
    上传者