Kickstart Practice Round 2017 Problem A. Country Leader

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int T = Integer.parseInt(in.nextLine());
		for (int t = 0; t < T; t++) {
			int N = Integer.parseInt(in.nextLine());
			String[] ori = new String[N];
			String[] order = new String[N];
			int[] longs = new int[N];
			for (int n = 0; n < N; n++) {
				String tp = in.nextLine();
				ori[n] = tp;
				tp = tp.replace(" ", "");
				TreeSet<Character> set = new TreeSet<Character>();
				for (int i = 0; i < tp.length(); i++) {
					set.add(tp.charAt(i));
				}
				longs[n] = set.size();
				StringBuilder sb = new StringBuilder();
				for (char c : set) {
					sb.append(c);
				}
				order[n] = sb.toString();
			}
			int max = -1;
			for (int i : longs) {
				if (max < i) {
					max = i;
				}
			}
			HashMap<String, Integer> map = new HashMap<String, Integer>();
			for (int i = 0; i < longs.length; i++) {
				if (longs[i] == max) {
					map.put(ori[i], i);
				}
			}
			int tpi = 0;
			while (map.size() > 1) {
				char c = 'Z';
				for (String s : map.keySet()) {
					if (c > s.charAt(tpi)) {
						c = s.charAt(tpi);
					}
				}
				Iterator<String> it = map.keySet().iterator();
				while (it.hasNext()) {
					String s = it.next();
					if (c != s.charAt(tpi)) {
						it.remove();
						map.remove(s);
					}
				}
				tpi++;
			}
			String re = "";
			for (String s : map.keySet()) {
				re = s;
			}
			System.out.println("Case #" + (t + 1) + ": " + re);
		}

	}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值