2012-02-29 4 views
-3

다음은 문제의 링크입니다. 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++; 
    } 
} 

} 대신 긴 코드를 디버깅하기 위해 다른 사람을 말하는

+3

잘못된 대답을 주면 완벽하게 작동하지 않습니다. 또한 사람들은 코드를 디버깅하지 않을 것입니다. 여기에서 대답 할 수 있다고 생각되는 특정 질문이 있습니까? – simchona

+0

uva가 RE를 제공하는 이유는 모르겠지만 프로그래밍상의 문제는 WA를 제공합니다. –

+0

RE 및 WA 란 무엇입니까? – simchona

답변

2

, 당신은 UVA 문제에 대한 주어진 입력에 대한 출력을 생성하고 솔루션을 비교하는 this site를 사용할 수 있습니다. 약 1500 가지 문제를 지원합니다.

+0

감사합니다. 아마도 형식 문제 때문일 수 있습니다. 나는 비교할 것이다. –

0

같은 문제, 지뢰 찾기, 출력 만 필드 # N 및 필드 번호의 N + 1 사이에 있는지 빈 줄을, URL http://www.programming-challenges.com/pg.php?page=downloadproblem&probid=110102&format=html

은 "프리젠 테이션 오류"얻는 경우에 있습니다. 앞뒤에 빈 줄이 없어야합니다. 여기

배쉬에 표시해야 '샘플 출력'을 제공하는 방법입니다

$ java Main <input 
Field #1: 
*100 
2210 
1*10 
1110 

Field #2: 
**100 
33200 
1*100 
$ 

공지 사항 하나의 빈 줄 필드 # 2 전 : 라인.

관련 문제