이클립스에서는 잘되는데 인터넷에서 제출하라고 했는데
계속 문제가 생겨 뭐가 문제인지 함 봐주라.
미니 스도쿠는 가로 넷 세로 넷, 총 16개의 칸으로 이루어져 있다. 각 가로줄과 각 세로줄, 그리고 각 2 X 2 네모 (왼쪽 위 네 칸, 왼쪽 아래 네 칸, 오른쪽 위 네 칸, 오른쪽 아래 네 칸)에 1, 2, 3, 4가 한 번씩 있어야 정답으로 인정된다. 예를 들어
2 1 4 3
1 2 3 4
4 3 2 1
3 4 1 2
이 스도쿠는 각 가로줄과 세로줄에는 1, 2, 3, 4가 한 번씩 들어가 있지만 왼쪽 위 네 칸에 3이랑 4가 없으므로 오답이다.
입력 첫 줄에는 스도쿠의 개수 n이 있다. 그 후 n개의 스도쿠가 있는데, 스도쿠 사이에는 빈 줄이 하나씩 있다. 각 스도쿠에 대해 정답이면 Correct, 오답이면 Incorrect를 출력하라.
입력
2
2 1 4 3
4 3 2 1
1 2 3 4
3 4 1 2
2 1 4 3
4 3 2 1
1 2 3 4
3 4 1 3
출력
Correct
Incorrect
2 1 4 3
1 2 3 4
4 3 2 1
3 4 1 2
이 스도쿠는 각 가로줄과 세로줄에는 1, 2, 3, 4가 한 번씩 들어가 있지만 왼쪽 위 네 칸에 3이랑 4가 없으므로 오답이다.
입력 첫 줄에는 스도쿠의 개수 n이 있다. 그 후 n개의 스도쿠가 있는데, 스도쿠 사이에는 빈 줄이 하나씩 있다. 각 스도쿠에 대해 정답이면 Correct, 오답이면 Incorrect를 출력하라.
입력
2
2 1 4 3
4 3 2 1
1 2 3 4
3 4 1 2
2 1 4 3
4 3 2 1
1 2 3 4
3 4 1 3
출력
Correct
Incorrect
import java.util.Scanner;
public class P3 {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int n;
int check[] = new int[3];
int [][] Sudoku;
String[] s;
System.out.println("input n:");
while(1==1){ //프로그맹 반복
s=sc.nextLine().split(" ");
n = Integer.parseInt(s[0]) * 2; //n값 받기
Sudoku = new int[n][n];
int count = 0;
checkSudoku checker = new checkSudoku(n);
while(count<2){
for(int i = 0; i<n; i++){
s=sc.nextLine().split(" ");
if(!"".equals(s[0])){ //널값을 맏지 않으면 입력
for(int j =0; j<n; j++){
Sudoku[i][j]=Integer.parseInt(s[j]);
}
}
else //널을 받으면 되돌린다.
--i;
}
checker.inputnumber(Sudoku); //클래스에서 값을 입력
check[count] = checker.checker(); //클래스에서 값을 받는다.
count++;
}
count = 0;
while(count<2){
if(check[count]==1) //받은값에 따라 값을 출력한다.
System.out.println("Incorrect");
else
System.out.println("Correct");
count++;
}
}
}
}
class checkSudoku{
private int n;
private int[][] Sudoku;
private int[] present;
public checkSudoku(int n){
this.n = n;
present = new int[n+1];
}
public void inputnumber(int[][] Sudoku){
this.Sudoku = Sudoku;
}
public int checker(){ //클래스를 실행.
int incorrect = 0;
incorrect =this.widthchecker();
if(incorrect!=1){
incorrect = this.heighchecker();
if(incorrect!=1){
incorrect = this.nchecker();
}
}
return incorrect;
}
public void resetpresent(){ //확인값 리셋
for(int i = 1; i< n+1; i++){
present[i] = 0;
}
}
public int widthchecker(){ //가로값 확인
int incorrect = 0;
for(int i =0 ; i< n; i++){
resetpresent();
for(int j = 0; j<n; j++){
if(Sudoku[i][j]>n||present[Sudoku[i][j]]==1){
incorrect = 1;
break;
}
else
present[Sudoku[i][j]]=1;
}
}
return incorrect;
}
public int heighchecker(){ //세로값 확인
int incorrect = 0;
for(int i =0 ; i< n; i++){
resetpresent();
for(int j = 0; j<n; j++){
if(Sudoku[j][i]>n||present[Sudoku[j][i]]==1){
incorrect = 1;
break;
}
else
present[Sudoku[j][i]]=1;
}
}
return incorrect;
}
public int nchecker(){ //N*N개 확인
int incorrect = 0;
resetpresent();
for(int i =0 ; i< n/2; i++){
for(int j = 0; j<n/2; j++){
if(Sudoku[j][i]>n||present[Sudoku[j][i]]==1){
incorrect = 1;
break;
}
else
present[Sudoku[j][i]]=1;
}
}
resetpresent();
for(int i =n/2 ; i< n; i++){
for(int j = 0; j<n/2; j++){
if(Sudoku[j][i]>n||present[Sudoku[j][i]]==1){
incorrect = 1;
break;
}
else
present[Sudoku[j][i]]=1;
}
}
resetpresent();
for(int i =0 ; i< n/2; i++){
for(int j = n/2; j<n; j++){
if(Sudoku[j][i]>n||present[Sudoku[j][i]]==1){
incorrect = 1;
break;
}
else
present[Sudoku[j][i]]=1;
}
}
resetpresent();
for(int i =n/2 ; i< 2; i++){
for(int j = n/2; j<2; j++){
if(Sudoku[j][i]>n||present[Sudoku[j][i]]==1){
incorrect = 1;
break;
}
else
present[Sudoku[j][i]]=1;
}
}
return incorrect;
}
지금 저걸 돌려 보라고?
이클립스에서는 잘되는데 인터넷 제출에서
Exception: java.util.NoSuchElementException Maybe at: at P3.main(P3.java:12) === TEST 2 === Exception: java.lang.ArrayIndexOutOfBoundsException Maybe at: at P3.main(P3.java:22) === TEST 3 === Exception: java.lang.ArrayIndexOutOfBoundsException Maybe at: at P3.main(P3.java:22)
이렇게 뜨는데 왜 이러는지 모르겠어...
xy 신드롬은 뭐야?
지금 문제가 이클립스에서는 돌아가는데 인터넷에 제출하면 안돌아가는데 이클립스 말고 다른거를 안돌려봐서 뭘해야될지 전혀 모르겠어
예외를 던지는 함수를 쓰면서 예외처리를 안해줬겠지.