코드비교

Old VersionNew Version
1import java.util.*; 1import java.util.Scanner;
2public class Main { 2public class Main { 
3public static void main(String args[]) { 3public static void main(String args[]) { 
4Scanner sc = new Scanner(System.in); 4Scanner sc = new Scanner(System.in); 
import java.util.*;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int start = 7;
int[] cols = new int[8];
int[] rows = new int[8];
int[] diag = new int[start * 2 + 1];
for (int i = 0; i < 8; i++) {
String line = sc.nextLine();
for (int j = 0; j < 8; j++) {
if (line.charAt(j) == 'Q') {
rows[i]++;
cols[j]++;
diag[start + (j - i)]++;
if (cols[j] > 1 || rows[i] > 1 || diag[start + (j - i)] > 1) {
System.out.println("Invalid");
return;
}
}
}
}
System.out.println("Valid");
}
}
import java.util.Scanner;
public class Main {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
int start = 7;
int[] cols = new int[8];
int[] rows = new int[8];
int[] diag = new int[start * 2 + 1];
for (int i = 0; i < 8; i++) {
String line = sc.nextLine();
for (int j = 0; j < 8; j++) {
if (line.charAt(j) == 'Q') {
rows[i]++;
cols[j]++;
diag[start+(j-i)]++;
if (cols[j] > 1 || rows[i] > 1 || diag[start + (j - i)] > 1) {
System.out.println("Invalid");
return;
}
}
}
}
System.out.println("Valid");
}
}