题目比较简单,就是好好熟悉一下答题系统,练练手
package leetcode152; import java.io.*; import java.util.Scanner; public class GoogleTest { public static void main(String[] args) throws Exception { String filename = "A-large-practice.in"; System.setIn(new FileInputStream(filename)); System.setOut(new PrintStream(new FileOutputStream("A-large-practice-out.txt"))); Scanner scanner = new Scanner(System.in); GoogleTest ll = new GoogleTest(scanner); scanner.close(); } public GoogleTest(Scanner in){ int testSize = Integer.valueOf(in.nextLine()); // System.out.println(testSize); for (int i = 0; i < testSize; i++){ String tt = in.nextLine(); int Num = Integer.valueOf(tt); String ans = in.nextLine(); for (int j = 1; j < Num; j++){ ans = Compare(ans, in.nextLine()); } System.out.println("Case #" + (i+1) + ": " +ans); } } public String Compare(String str1, String str2){ boolean[] Str1 = new boolean[26]; int num1 = 0; for (int i = 0; i < str1.length(); i++){ if (str1.charAt(i) == ' '){ continue; } int num = str1.charAt(i) - 'A'; if (Str1[num] == false){ Str1[num] = true; num1++; } } boolean[] Str2 = new boolean[26]; int num2 = 0; for (int i = 0; i < str2.length(); i++){ if (str2.charAt(i) == ' '){ continue; } int num = str2.charAt(i) - 'A'; if (Str2[num] == false){ Str2[num] = true; num2++; } } String ans = str1; if (num1 > num2){ ans = str1; } else if (num1 < num2){ ans = str2; } else { int i = 0; while ( i < str1.length() && i < str2.length()){ if (str1.charAt(i) > str2.charAt(i)){ return str2; } else if (str1.charAt(i) < str2.charAt(i)){ return str1; } else { i++; } } } // System.out.println(str1 + " " + num1 + " " + str2 + " " + num2 + " " + ans); return ans; } }