碰到一些怪怪的問題
丟 code 進去 run 出來的解題系統正確答案要求是 KLY (驗證碼為2)
而我的程式給出的答案是 JVX (驗證碼為3)
我試著用網路上現成的身分證字號產生器 丟會產生 KLY 和 JVX 的測資進去 run 出來的結果都正確
可是卻一直沒辦法通過解題系統的測試
以下是我的程式碼 還請先進過目
import java.util.Scanner;
public class JAVA {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
while (input.hasNext()) {
System.out.println(getIdFirstLetter(input.nextLine()));
}
}
// 輸入身分證後9碼,以取得有可能成為身分證英文字首的字串
public static String getIdFirstLetter(String idNumber) {
String idLetter = "";
// 把字串轉換成字元陣列
char charIdNumberArray[] = idNumber.toCharArray();
int intIdNumberArray[] = new int[charIdNumberArray.length];
int idSum = 0;
int countOfIdSum = 0;
final int A = 1, B = 10, C = 19, D = 28, E = 37;
final int F = 46, G = 55, H = 64, I = 39, J = 73;
final int K = 82, L = 2, M = 11, N = 20, O = 48;
final int P = 29, Q = 38, R = 47, S = 56, T = 65;
final int U = 74, V = 83, W = 21, X = 3, Y = 12;
final int Z = 30;
// 將字元陣列內的數字轉換成整數
for (int i = 0; i < intIdNumberArray.length; i++) {
intIdNumberArray[i] = charIdNumberArray[i] - 48;
}
// 計算第1到8位的身分證相對位數乘積總和
for (int i = 8; i > 0; i--) {
idSum = idSum + intIdNumberArray[countOfIdSum] * i;
countOfIdSum++;
}
// 擷取可能是身分證第一個字母的字元
if (intIdNumberArray[intIdNumberArray.length - 1] == (10 - ((idSum + A) % 10)))
idLetter += "A";
if (intIdNumberArray[intIdNumberArray.length - 1] == (10 - ((idSum + B) % 10)))
idLetter += "B";
if (intIdNumberArray[intIdNumberArray.length - 1] == (10 - ((idSum + C) % 10)))
idLetter += "C";
if (intIdNumberArray[intIdNumberArray.length - 1] == (10 - ((idSum + D) % 10)))
idLetter += "D";
if (intIdNumberArray[intIdNumberArray.length - 1] == (10 - ((idSum + E) % 10)))
idLetter += "E";
if (intIdNumberArray[intIdNumberArray.length - 1] == (10 - ((idSum + F) % 10)))
idLetter += "F";
if (intIdNumberArray[intIdNumberArray.length - 1] == (10 - ((idSum + G) % 10)))
idLetter += "G";
if (intIdNumberArray[intIdNumberArray.length - 1] == (10 - ((idSum + H) % 10)))
idLetter += "H";
if (intIdNumberArray[intIdNumberArray.length - 1] == (10 - ((idSum + I) % 10)))
idLetter += "I";
if (intIdNumberArray[intIdNumberArray.length - 1] == (10 - ((idSum + J) % 10)))
idLetter += "J";
if (intIdNumberArray[intIdNumberArray.length - 1] == (10 - ((idSum + K) % 10)))
idLetter += "K";
if (intIdNumberArray[intIdNumberArray.length - 1] == (10 - ((idSum + L) % 10)))
idLetter += "L";
if (intIdNumberArray[intIdNumberArray.length - 1] == (10 - ((idSum + M) % 10)))
idLetter += "M";
if (intIdNumberArray[intIdNumberArray.length - 1] == (10 - ((idSum + N) % 10)))
idLetter += "N";
if (intIdNumberArray[intIdNumberArray.length - 1] == (10 - ((idSum + O) % 10)))
idLetter += "O";
if (intIdNumberArray[intIdNumberArray.length - 1] == (10 - ((idSum + P) % 10)))
idLetter += "P";
if (intIdNumberArray[intIdNumberArray.length - 1] == (10 - ((idSum + Q) % 10)))
idLetter += "Q";
if (intIdNumberArray[intIdNumberArray.length - 1] == (10 - ((idSum + R) % 10)))
idLetter += "R";
if (intIdNumberArray[intIdNumberArray.length - 1] == (10 - ((idSum + S) % 10)))
idLetter += "S";
if (intIdNumberArray[intIdNumberArray.length - 1] == (10 - ((idSum + T) % 10)))
idLetter += "T";
if (intIdNumberArray[intIdNumberArray.length - 1] == (10 - ((idSum + U) % 10)))
idLetter += "U";
if (intIdNumberArray[intIdNumberArray.length - 1] == (10 - ((idSum + V) % 10)))
idLetter += "V";
if (intIdNumberArray[intIdNumberArray.length - 1] == (10 - ((idSum + W) % 10)))
idLetter += "W";
if (intIdNumberArray[intIdNumberArray.length - 1] == (10 - ((idSum + X) % 10)))
idLetter += "X";
if (intIdNumberArray[intIdNumberArray.length - 1] == (10 - ((idSum + Y) % 10)))
idLetter += "Y";
if (intIdNumberArray[intIdNumberArray.length - 1] == (10 - ((idSum + Z) % 10)))
idLetter += "Z";
// 回傳可能為身分證第一個字母的字串
return idLetter;
}
}