무제
[백준] 1158번 요세푸스 문제 본문
import sys
input = sys.stdin.readline
n, start = map(int, input().split())
people = [i for i in range(1, n+1)]
answer = []
num = 0
for _ in range(n):
num += start-1
if num >= len(people):
num = num%len(people)
answer.append(str(people.pop(num)))
print("<",", ".join(answer)[:],">", sep='')
start index대로 제거하되, 남은 사람들의 길이를 초과할 경우
num%len(people)을 통해 num을 초기화시켜주면 해결할 수 있는 간단한 문제인데
틀렸다..
'Study > Coding Test 오답노트' 카테고리의 다른 글
| [백준] 10799번 쇠막대기 (2) | 2024.11.13 |
|---|---|
| [백준] 17413번 단어뒤집기 2 (0) | 2024.11.12 |
| [백준] 1406번 에디터 (0) | 2024.11.09 |
| [백준] 자료구조 - 9012(괄호) / 1874(스택 수열) (0) | 2024.10.19 |
| 백준 알고리즘 공부 순서 (0) | 2024.10.19 |
Comments