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);
}
}
Kickstart Practice Round 2017 Problem A. Country Leader
最新推荐文章于 2022-04-16 21:06:32 发布