• 문제 링크
10328번: Jury Jeopardy
On the first line one positive number: the number of test cases, at most 100. After that per test case: one line with two space-separated integers h and w (3 ≤ h, w ≤ 100): the height and width of the maze, respectively. h lines, each with w characters
www.acmicpc.net
• 풀이 코드
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
StringBuilder sb = new StringBuilder();
int t = Integer.parseInt(br.readLine());
sb.append(t).append("\n");
int[][] dir = {{0, 1}, {1, 0}, {0, -1}, {-1, 0}};
while (t-- > 0) {
char[] arr = br.readLine().toCharArray();
boolean[][] mat = new boolean[200][100];
int cur = 0, y = 100, x = 0, top = 100, bot = 0, right = 0;
mat[y][x] = true;
for (char c : arr) {
switch (c) {
case 'F':
y += dir[cur][0];
x += dir[cur][1];
break;
case 'R':
cur = (cur + 1) % 4;
y += dir[cur][0];
x += dir[cur][1];
break;
case 'B':
cur = (cur + 2) % 4;
y += dir[cur][0];
x += dir[cur][1];
break;
case 'L':
cur = (cur + 3) % 4;
y += dir[cur][0];
x += dir[cur][1];
break;
}
mat[y][x] = true;
top = Math.min(top, y);
bot = Math.max(bot, y);
right = Math.max(right, x);
}
sb.append(++bot - --top + 1).append(" ").append(++right + 1).append("\n");
for (int i = top; i <= bot; i++, sb.append('\n'))
for (int j = 0; j <= right; j++) sb.append(mat[i][j] ? '.' : '#');
}
bw.write(sb.toString());
bw.flush();
}
}
'Problem Solving > Baekjoon' 카테고리의 다른 글
[백준] 27563 Moo Operations - Greedy / Java (0) | 2024.02.10 |
---|---|
[백준] 11255 ITAI Virus - Graph Theory / Java (0) | 2024.02.09 |
[백준] 8073 Road Net - Graph Theory / Java (0) | 2024.02.07 |
[백준] 17848 Flight Turbulence - Graph Theory / Java (0) | 2024.02.06 |
[백준] 31217 Y - Graph Theory / Java (0) | 2024.02.05 |
댓글