1 条题解

  • 0
    @ 2023-6-11 12:21:10

    C++ :

    #include <bits/stdc++.h>
    using namespace std;
    int main(){
        int n,a[110],i;
        cin>>n;
        for(i = 1;i <= n;i++){
        	cin>>a[i];
    	}
    	
    	int c1 = 0;
    	int c2 = 0;
    	
    	for(i = 1;i < n;i++){
    		if(a[i] == 10) c1++;
    		else c2++;
    	}
    	
    	if(c1 > c2){
    		cout<<10;
    	}else{
    		cout<<20;
    	}
        return 0;
    }
    

    Java :

    import java.util.Scanner;
    public class Main {
        public static void main(String[] args) {
            Scanner scanner = new Scanner(System.in);
            int num1 = scanner.nextInt();
    //        int num2 = scanner.nextInt();
            int[] a = new int[num1];
            int count1 = 0,count2 = 0, count3 = 0;
            for (int i = 0; i < num1; i++) {
                a[i] = scanner.nextInt();
            }
            for (int i = 0; i < num1; i++) {
                if(a[i] == 10)count1++;
                else if(a[i] == 20) count2++;
            }
            if(count1 > count2)
            System.out.println(10);
            else System.out.println(20);
    
        }
    
        public static boolean judge(int i,int j){
            int a,s = 0;
            while(i != 0){
                a = i % 10;
                s = s + a;
                i /= 10;
            }
            if(s == j)return true;
            else return false;
        }
    
        public static void paiXu(int[] a){
            int temp;
            for(int i = 0;i < a.length - 1;i++){
                for(int k = 0;k < a.length - i - 1;k++){
                    if(a[k] > a[k + 1]){
                        temp = a[k];
                        a[k] = a[k + 1];
                        a[k + 1] = temp;
                    }
                }
            }
        }
    }
    

    Python :

    n=int(input())
    s1=list(map(int,input().split()))
    a10=len([item for item in s1 if item==10])
    a20=len([item for item in s1 if item==20])
    if a10>a20:
        print("10")
    else:
        print("20")
    
    
    
    
    
    • 1

    信息

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