import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int N = input.nextInt();
input.nextLine();
String[] Numbers = new String[N];
for (int i = 0; i < N; i++)
Numbers[i] = input.nextLine();
for (int i = 0; i < N; i++) {
String result = (validate(Numbers[i])) ? "Valid" : "Invalid";
System.out.println(result);
}
}
private static boolean validate(String cardNum) {
String reverseCardNum = new StringBuffer(cardNum).reverse().toString();
int oddSum = 0;
int evenSum = 0;
for (int i = 0; i < cardNum.length(); i++) {
if (i % 2 == 1)
evenSum += encryptToNumber(reverseCardNum.charAt(i));
else
oddSum += reverseCardNum.charAt(i) - '0';
}
return (evenSum + oddSum) % 10 == 0;
}
private static int encryptToNumber(char c) {
int n = (c - '0') * 2;
int result = n % 10;
result += n / 10;
return result;
}
}
예시는 잘 출력됩니다만 WA가 뜨네요. 어디서 놓친 게 있을까요?