728x90
📌 문제
https://swexpertacademy.com/main/main.do
📌 문제 접근 방법
- N을 4로 나눠서 cnt에 저장하고 그만큼 회전을 시켜서 숫자를 생성하였다.
- 생성한 숫자는 four_num함수를 사용하여 4개로 잘라서 total에 저장하였다.
- total에서 중복을 제거한 후 내림차순으로 정렬하여 K번째에 있는 수를 10진수로 변환하였다.
📌 코드
# SWEA 5658 보물상자 비밀번호
from collections import deque
def four_num(num):
global total
i = 0
for _ in range(4):
temp = ''
for j in range(i, i+cnt):
temp += num[j]
total.append(temp)
i += cnt
T = int(input())
for t in range(1, T+1):
N, K = map(int, input().split())
num = deque(input())
cnt = N//4
total = []
for _ in range(cnt):
four_num(num)
num.append(num.popleft())
total = list(set(total))
total.sort(reverse=True)
target = int(total[K-1], 16)
print('#{} {}'.format(t, target))
728x90
'ALGORITHM > SW Expert Academy' 카테고리의 다른 글
[SWEA/Python] 2383. 미생물 격리 (0) | 2021.12.07 |
---|---|
[SWEA/Python] 2383. 점심 식사시간 (0) | 2021.12.07 |
[SWEA/Python] 1795. 인수의 생일 파티 (0) | 2021.10.19 |
[SWEA/Python] 1249. 보급로 (0) | 2021.10.19 |
[SWEA/Python] 7465. 창용 마을 무리의 개수 (0) | 2021.10.15 |
댓글