728x90
▶ 상하좌우
n = int(input())
plans = input().split()
x, y = 1, 1
dx=[0,0,-1,1]
dy=[-1,1,0,0]
move_type=['L','R','U','D']
for plan in plans:
for i in range(len(move_type)):
if plan == move_type[i]:
nx = dx[i] + x
ny = dy[i] + y
# 공간을 벗어나는 경우 무시
if nx < 1 or ny < 1 or nx > n or ny > n:
continue
x, y = nx, ny
print(x, y)
▶ 시각
h = int(input())
count = 0
for i in range(h + 1):
for j in range(60):
for k in range(60):
#매 시각에 3이 포함되어 있으면 count 증가
if '3' in str(i)+str(j)+str(k):
count += 1
print(count)
▶ 왕실의 나이트
data = input()
row=int(data[1])
column = int(ord(data[0])) - int(ord('a')) + 1
#나이트가 이동할 수 있는 8가지 방향
steps = [(-2,-1),(-1,-2),(-1,2),(-2,1),(1,-2),(2,-1),(1,2),(2,1)]
result = 0
for step in steps:
next_row = row + step[0]
next_column = column + step[1]
if next_row >=1 and next_row <=8 and next_column >=1 and next_column <=8:
result += 1
print(result)
▶ 문자열 재정렬
data = input()
result = []
value = 0
for x in data:
if x.isalpha():
result.append(x)
else:
value += int(x)
result.sort()
if value!=0:
result.append(str(value))
print(''.join(result))
728x90
'💻 알고리즘 > 알고리즘' 카테고리의 다른 글
[ 이코테 ] 다이나믹 프로그래밍 (0) | 2021.04.06 |
---|---|
[ 이코테 ] 이진 탐색 알고리즘 (0) | 2021.04.03 |
[ 이코테 ] 정렬 알고리즘 (0) | 2021.04.01 |
[ 이코테 ] DFS & BFS 알고리즘 (0) | 2021.03.30 |
[ 이코테 ] 그리디(탐욕) 알고리즘 (0) | 2021.03.18 |