1 条题解

  • 0
    @ 2023-6-11 12:20:57

    C++ :

    #include<bits/stdc++.h>
    using namespace std;
    
    
    int main() {
    	int n,x,s1=0,s2=0,i;
    	cin>>n;
    	for(i = 1;i <= n;i++){
    		cin>>x;
    		if(i%2==1) s1+=x;
    		else s2+=x;
    	}
    	
    	cout<<"KING"<<" "<<s1<<endl;
    	cout<<"WIN"<<" "<<s2<<endl;
    	if(s1 >= s2){
    		cout<<"KING";
    	}else{
    		cout<<"WIN";
    	}
    }
    

    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 count = 0,s1 = 0 , s2 = 0;
            for (int i = 0; i < num1; i++) {
                a[i] = scanner.nextInt();
            }
    
            for (int i = 0; i < num1; i+=2) {
                s1 = s1 + a[i];
            }
            System.out.println("KING" + " " + s1);
            for (int i = 1; i < num1; i+=2) {
                s2 = a[i] + s2;
            }
            System.out.println("WIN" + " " + s2);
            if(s1 >= s2) System.out.println("KING");
            else System.out.println("WIN");
    
    
        }
    
        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()))
    sj=[item for index, item in enumerate(s1) if index%2==0]
    so=[item for index, item in enumerate(s1) if index%2==1]
    
    print("KING",sum(sj))
    print("WIN",sum(so))
    if sum(sj)>=sum(so):
        print("KING")
    else:
        print("win".upper())
        
    
    
    • 1

    信息

    ID
    2647
    时间
    1000ms
    内存
    128MiB
    难度
    7
    标签
    递交数
    20
    已通过
    9
    上传者