티스토리 뷰
백준 www.acmicpc.net/problem/1303 문제를 풀다가
NoSuchElement 에러가 발생하여 맞았는지 틀렸는지 확인이 안되는 상황이 있었다.
Before
public class Main {
public static int N, M, countW, countB;
public static char graph[][];
public static boolean visited[][];
static int[] moveW = new int[]{0, 1, 0, -1};
static int[] moveH = new int[]{1, 0, -1, 0};//위, 오른쪽, 아래, 왼
public static void main(String[] args) throws Exception {
Scanner sc = new Scanner(System.in);
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(bf.readLine());
N = Integer.parseInt(st.nextToken()); // 가로의 크기
M = Integer.parseInt(st.nextToken()); // 세로의 크기
graph = new char[M][N];
visited = new boolean[M][N];
for(int i=0; i<M ; i++){
graph[i] = sc.next().toCharArray(); // 입력
}
......생략
}
}
After
public class Main {
public static int N, M, countW, countB;
public static char graph[][];
public static boolean visited[][];
static int[] moveW = new int[]{0, 1, 0, -1};
static int[] moveH = new int[]{1, 0, -1, 0};//위, 오른쪽, 아래, 왼
public static void main(String[] args) throws Exception {
BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(bf.readLine());
N = Integer.parseInt(st.nextToken()); // 가로의 크기
M = Integer.parseInt(st.nextToken()); // 세로의 크기
graph = new char[M][N];
visited = new boolean[M][N];
for(int i=0; i<M ; i++){
String s = bf.readLine();
graph[i] = s.toCharArray(); // 입력
}
}
}
Before | After |
Scanner sc = new Scanner(System.in); |
--> Scanner 선언 부분 삭제. |
댓글