import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int i, j, k;
String[] input = new String[8];
int validity = 0; int nums = 0;
for (i=0; i<8; i++) input[i] = sc.nextLine();
for (i=0; i<8; i++){ //row
for (j=0; j<8; j++){
if (input[i].charAt(j)=='Q') nums++;
}
if (nums>=2) validity++;
nums = 0;
}
for (j=0; j<8; j++){ //column
for (i=0; i<8; i++){
if (input[i].charAt(j)=='Q') nums++;
}
if (nums>=2) validity++;
nums = 0;
}
for (i=0; i<8; i++){ //diagonal to the north-east
for (k=i, j=0; i>=0; i--, j++){
if (input[k].charAt(j) == 'Q') nums++;
}
if (nums>=2) validity++;
nums = 0;
}
for (j=7; j>=0; j--){
for (i=7, k=j; k<8; i--, k++){
if (input[i].charAt(k) == 'Q') nums++;
}
if (nums>=2) validity++;
nums = 0;
}
for (j=0; j<8; j++){
for (i=7, k=j; k>=0; i--, k--){
if (input[i].charAt(k) == 'Q') nums++;
}
if (nums>=2) validity++;
nums = 0;
}
for (i=0; i<8; i++){
for (k=i, j=7; k>=0; k--, j--){
if (input[k].charAt(j) == 'Q') nums++;
}
if (nums>=2) validity++;
nums = 0;
}
if (validity > 0) System.out.println("Invalid");
else System.out.println("Valid");
}
}
일단은 time limit exceed가 뜨고요,
인텔리 제이에서 실행했을 땐, sc.nextLine의 입력을 무한히 받기만 하고 아래의 for문들이 실행이 안되는 것 같습니다