Under my umbrella.

SKII

Less is more.

洛谷 P1781 宇宙总统(JAVA)

洛谷 P1781 宇宙总统

import java.util.Scanner;

public class Main {
    public static boolean bigger(String score, String now) {
        boolean flag = true;
        if(score.length() < now.length()) {
            flag = true;
        } else if(score.length() > now.length()) {
            flag = false;
        } else {
            for(int i = 0; i < now.length(); i++) {
                if(now.charAt(i) < score.charAt(i)) {
                    flag = false;
                    break;
                } else if (now.charAt(i) > score.charAt(i)){
                    flag = true;
                    break;
                }
            }
        }
        return flag;
    }
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int num = 0;
        String score = "0";
        for(int i = 0; i < n; i++) {
            String now = scan.next();
            if(bigger(score, now)) {
                score = now;
                num = i+1;
            }
        }
        System.out.println(num);
        System.out.println(score);
    }
}
posted @ 2020-02-20 15:20  NLYang  阅读(121)  评论(0编辑  收藏  举报