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]);}}
}