다음은 문제의 링크입니다. http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=13&page=show_problem&problem=1130uva 10189 지뢰 찾기
이것은 내 코드이며 완벽하게 작동합니다. 그러나, 그것을 제출할 때마다 틀린 대답을합니다. 왜 아무도 알지 못해?
참고 : 행의 첫 번째 열 또는 마지막 행의 왼쪽을 검사 할 때 오류가 발생하지 않도록 행을 2 개의 여분의 행과 열로 채 웁니다.
public class Main {
public void convert(char[][] maze, int fieldNum) {
if (fieldNum != 1)
System.out.println();
System.out.println("Field #" + fieldNum + ":");
int n = maze.length;
int m = maze[0].length;
char[][] result = new char[n][];
for (int i = 0; i < n; i++) {
result[i] = new char[m];
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
result[i][j] = '0';
}
}
for (int i = 1; i < n - 1; i++) {
for (int j = 1; j < m - 1; j++) {
if (maze[i][j] == '*') {
this.fill(result, i, j);
}
}
}
for (int i = 1; i < n - 1; i++) {
for (int j = 1; j < m - 1; j++) {
System.out.print(result[i][j]);
}
System.out.println();
}
}
private void fill(char[][] maze, int i, int j) {
if (maze[i-1][j-1] != '*')
maze[i-1][j-1] += 1;
if (maze[i][j-1] != '*')
maze[i][j-1] += 1;
if (maze[i+1][j-1] != '*')
maze[i+1][j-1] += 1;
if (maze[i-1][j] != '*')
maze[i-1][j] += 1;
maze[i][j] = '*';
if (maze[i+1][j] != '*')
maze[i+1][j] += 1;
if (maze[i-1][j+1] != '*')
maze[i-1][j+1] += 1;
if (maze[i][j+1] != '*')
maze[i][j+1] += 1;
if (maze[i+1][j+1] != '*')
maze[i+1][j+1] += 1;
}
public static void main(String[] args) throws IOException {
Main sweeper = new Main();
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String line = null;
int fieldNum = 1;
while ((line = reader.readLine()) != null) {
String[] xy = line.trim().split("\\s+");
int n = Integer.parseInt(xy[0]);
int m = Integer.parseInt(xy[1]);
if (n == 0 && m == 0)
break;
n += 2;
m += 2;
char[][] maze = new char[n][];
for (int i = 0; i < n; i++) {
maze[i] = new char[m];
}
for (int i = 1; i < n - 1; i++) {
line = reader.readLine();
for (int j = 1; j < n - 1; j++) {
maze[i][j] = line.charAt(j - 1);
}
}
sweeper.convert(maze, fieldNum);
fieldNum++;
}
}
} 대신 긴 코드를 디버깅하기 위해 다른 사람을 말하는
잘못된 대답을 주면 완벽하게 작동하지 않습니다. 또한 사람들은 코드를 디버깅하지 않을 것입니다. 여기에서 대답 할 수 있다고 생각되는 특정 질문이 있습니까? – simchona
uva가 RE를 제공하는 이유는 모르겠지만 프로그래밍상의 문제는 WA를 제공합니다. –
RE 및 WA 란 무엇입니까? – simchona