반응형
* 상하좌우
n = int(input())
a = input().split()
_dict = { 'R': (0, 1), 'L': (0. -1), 'U': (-1, 0), 'D': (1, 0) }
location_v = 1
location_h = 1
while a:
direction = a.pop(0)
if direction == 'R' and location_h == n:
pass
elif direction == 'L' and location_h == 1:
pass
elif direction == 'U' and location_v == 1:
pass
elif direction == 'D' and location_v == n:
pass
else:
location_v += _dict[direction][0]
location_h += _dict[direction][1]
print(f'{location_v} {location_h}')
n = int(input())
a = input().split()
_dict = { 'R': (0, 1), 'L': (0. -1), 'U': (-1, 0), 'D': (1, 0) }
location_v = 1
location_h = 1
while a:
direction = a.pop(0)
if (direction == 'R' and location_h == n) or (direction == 'L' and location_h == 1) \
or (direction == 'U' and location_v == 1) or (direction == 'D' and location_v == n):
pass
else:
location_v += _dict[direction][0]
location_h += _dict[direction][1]
print(f'{location_v} {location_h}')
** 위 문제 답안 예시
답안 보니 나는 의도대로 푼 게 아닌 듯
* 시각
N = int(input())
hour = [str(i) for i in range(N + 1)]
minute = [str(i) for i in range(60)]
second = [str(i) for i in range(60)]
answer = 0
for h in hour:
for m in minute:
for s in second:
if '3' in h+m+s:
answer += 1
print(answer)
* 왕실의 나이트
v = [ "a", "b", "c", "d", "e", "f", "g", "h"]
wh = []
for i in range(1, 9):
w = []
for j in range(1, 9):
w.append([i, j])
wh.append(w)
kn = [
(2, 1), (2, -1), (-2, 1), (-2, -1),
(1, 2), (-1, 2), (1, -2), (-1, -2)
]
location = input()
i = int(location[1]) - 1
j = v.index(location[0])
placed = wh[i][j]
answer = 0
for k in kn:
if placed[0] + k[0] > 8 or placed[0] + k[0] < 1 or placed[1] + k[1] > 8 or placed[1] + k[1] < 1:
continue
else:
answer += 1
print(answer)
** 예시 답안
* 문자 재정렬
st = input()
temp = []
sum_ = 0
num_cnt = 0
for s in st:
if s.isalpha():
temp.append(s)
else:
num_cnt += 1
sum_ += int(s)
temp.sort()
x = "".join(temp)
y = "" if num_cnt == 0 else str(sum_)
print(f'{x}{y}')
** 문자 재정렬 예시 답안
반응형
'Algorithm > 알고리즘 스터디(2021.12)' 카테고리의 다른 글
[이코테] 4. 정렬 알고리즘 (0) | 2022.02.14 |
---|---|
[이코테] dfs, bfs 복습 (0) | 2022.02.14 |
[이코테] dfs & bfs 문제풀이 (0) | 2022.02.08 |
[이것이코딩테스트다][MEMO] 10, 11강, 12강, 13강 (0) | 2021.12.20 |
[이것이코딩테스트다][MEMO] 4, 5, 6, 7, 8, 9강 (0) | 2021.12.14 |