개발자 톡
연습문제 톡
[HSAT 1회 정기 코딩 인증평가 기출] 로봇이 지나간 경로
Subtask2 몇 문제 오답: 반례나 문제점을 찾는거 도와주시면 정말 감사하겠습니다ㅠㅠ
- 등록일
- 2024-08-29 19:08:12
- 조회수
- 156
- 작성자
- shane16
Subtask2에 몇 문제만 오답이 뜨는데 무엇을 빠뜨린것인지 모르겠습니다ㅜㅜ
반례나 문제점 지적해주실 수 있으신 고수님들 도와주시면 감사하겠습니다ㅠㅠ
h, w = map(int,input().split()) grid = [list(input()) for _ in range(h)] order = [] directions = {'^':0,'<':1,'v':2, '>':3} def search_4(i,j): way = 0 if j>=1: if grid[j-1][i] == '#': way += 1 direction = '^' if i>=1: if grid[j][i-1] == '#': way += 1 direction = '<' if j < h-1: if grid[j+1][i] == '#': way += 1 direction = 'v' if i < w-1: if grid[j][i+1] == '#': way += 1 direction = '>' return way, direction def find_start(): for i in range(w): for j in range(h): if grid[j][i] == '#': way, direction = search_4(i,j) if way==1: return i,j, direction def move(x, y, direction): nx,ny = x,y grid[y][x] = '.' if direction == '>': grid[y][x+1] = '.' nx += 2 elif direction == '<': grid[y][x-1] = '.' nx -= 2 elif direction == '^': grid[y-1][x] = '.' ny -= 2 else: # 'v' grid[y+1][x] = '.' ny += 2 order.append('A') return nx,ny def search_dir(i,j): if j>=1: if grid[j-1][i] == '#': return '^' if i>=1: if grid[j][i-1] == '#': return '<' if j < h-1: if grid[j+1][i] == '#': return 'v' if i < w-1: if grid[j][i+1] == '#': return '>' return None def turn(prevD,D): diff = directions[prevD] - directions[D] # print(diff) if diff == -1 or diff == 3: order.append('L') elif diff == -3 or diff == 1: order.append('R') def find_order(startX,startY,startD): nx,ny = move(startX, startY, startD) direction = search_dir(nx,ny) prev_direction = direction while direction is not None: if direction != prev_direction: # print(prev_direction, direction) turn(prev_direction,direction) nx,ny = move(nx,ny,direction) prev_direction = direction direction = search_dir(nx,ny) # print(direction) # 1. 위치 찾기 startX, startY, startD = find_start() print(startY+1,startX+1) print(startD) # 2. 명령어 찾기 find_order(startX,startY,startD) # print(grid) for x in order: print(x,end='')
#[HSAT_1회_정기_코딩_인증평가_기출]_로봇이_지나간_경로