同樣的程式邏輯 c276 可以AC
但在這邊就會TLE
算了,這題放棄。
package 高中生程式解題系統;
import java.util.Scanner;
public class Test_a291_XX {
/**
* a291: nAnB problem
*
* @param args
*/
public static void main(String[] args) {
Scanner cin = new Scanner(System.in);
while (cin.hasNext()) {
// 讀入答案資料
String startAnswerStr = cin.nextLine();
String[] startAnswerList = startAnswerStr.split(" ");
// 空白跳過
if (startAnswerList[0].isEmpty()) {
continue;
}
// 讀入資料總比數
int count = cin.nextInt();
cin.nextLine();
for (int k = 0; k < count; k++) {
// 讀取測試資料
String inputStr = cin.nextLine();
String[] inputList = inputStr.split(" ");
int a = 0, b = 0;
String[] startAnswer = startAnswerList.clone();
for (int j = 0; j < inputList.length; j++) {
if (startAnswer[j].equals(inputList[j])) {
a++;
startAnswer[j] = "";
inputList[j] = "A";
}
}
for (int j = 0; j < inputList.length; j++) {
if (startAnswer[(j + 1) % 4].equals(inputList[j])) {
b++;
continue;
} else if (startAnswer[(j + 2) % 4].equals(inputList[j])) {
b++;
continue;
} else if (startAnswer[(j + 3) % 4].equals(inputList[j])) {
b++;
continue;
}
}
System.out.println(a + "A" + b + "B");
a = 0;
b = 0;
}
}
cin.close();
}
}