티스토리 뷰
출저 : https://www.acmicpc.net/problem/1347
"시뮬레이션"
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; class Main { static int N; static char[][] map = new char[250][250]; static int maxX; static int maxY; static int minX; static int minY; static int sx; static int sy; static int d = 2; // S static int[] dx = {-1,0,1,0}; static int[] dy = {0,1,0,-1}; static StringBuffer sb = new StringBuffer(); public static void main (String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); N = Integer.parseInt(br.readLine()); char[] cmd = br.readLine().toCharArray(); for (int i = 0; i < 250; i++) { Arrays.fill(map[i], '#'); } maxX = maxY = minX = minY = sx = sy = 49; map[sx][sy] = '.'; for (int i = 0; i < cmd.length; i++) { char c = cmd[i]; if(c == 'F') { sx += dx[d]; sy += dy[d]; map[sx][sy] = '.'; maxX = Math.max(maxX, sx); minX = Math.min(minX, sx); maxY = Math.max(maxY, sy); minY = Math.min(minY, sy); } else { d = turn(c,d); } } for (int i = minX; i <= maxX; i++) { for (int j = minY; j <= maxY; j++) { sb.append(map[i][j]); } sb.append("\n"); } System.out.print(sb.toString()); } static int turn(char cmd, int d) { if(cmd == 'R') return d + 1 == 4 ? 0 : d + 1; return d - 1 == -1 ? 3 : d - 1; } } | cs |
'Study > 알고리즘 문제풀이' 카테고리의 다른 글
백준 3006. 터보소트 :: 돼지개발자 (0) | 2018.11.16 |
---|---|
백준 6087. 레이저 통신 :: 돼지개발자 (0) | 2018.11.15 |
백준 2980. 도로와 신호등 :: 돼지개발자 (0) | 2018.11.15 |
백준 3985. 롤 케이크 :: 돼지개발자 (0) | 2018.11.15 |
백준 3197. 백조의 호수 :: 돼지개발자 (0) | 2018.11.13 |
댓글
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday