HDOJ 1004 Let the Balloon Rise

来源:互联网 发布:淘宝买家匿名提取软件 编辑:程序博客网 时间:2024/06/14 06:42

HDACM1004
此题思路较为简单,找到出现最多的就记录那个色球下标就好了

import java.util.Scanner;public class Main{    public static void main(String[] args) {        Scanner sc = new Scanner(System.in);        while (sc.hasNext()) {            int n = sc.nextInt();            if (n==0) {                break;            }            String[] strs = new String[n];            for (int i = 0; i < strs.length; i++) {                strs[i] = sc.next();            }            int max = 0;            int max_i = 0;            for (int i = 0; i < strs.length; i++) {                int count = 1;                for (int j = i+1; j < strs.length; j++) {                    if (strs[i].equals(strs[j])) {                        count++;                    }                }                if (max<count) {                    max = count;                    max_i = i;                }            }            System.out.println(strs[max_i]);        }    }}
原创粉丝点击