구현 알고리즘이란?
문제 1 - 상하좌우
풀이
n = int(input())
x,y = 1,1
plans = input().split()
dx = [0,0,-1,1]
dy = [-1,1,0,0]
move = ['L','R','U','D']
for plan in plans:
for i in range(len(move)):
if plan == move[i]:
nx = x + dx[i]
ny = y + dy[i]
if nx < 1 or ny < 1 or nx > n or ny > n:
continue
x,y = nx, ny
print(x,y)
문제 2 - 시각
풀이
h = int(input())
cnt = 0
for i in range(h+1):
for j in range(60):
for k in range(60):
if '3' in str(i)+str(j)+str(k):
cnt += 1
print(cnt)
문제 3 - 왕실의 나이트
풀이
data = input()
row = int(data[1])
col = int(ord(data[0])) - int(ord('a')) + 1
steps = [(-2,-1),(-2,1),(2,-1),(2,1),(-1,-2),(-1,-2),(1,-2),(1,2)]
cnt = 0
for step in steps:
n_row = row + step[0]
n_col = col + step[1]
if n_row >= 1 and n_row <= 8 and n_col >= 1 and n_col <= 8:
cnt += 1
print(cnt)