์•Œ๊ณ ๋ฆฌ์ฆ˜

๋ฐฑ์ค€ 11866 ์š”์„ธํ‘ธ์Šค ๋ฌธ์ œํ’€์ด

ghtis1798 2021. 3. 23. 12:29

๐Ÿ“Œ๋ฌธ์ œ์„ค๋ช…

๋ฌธ์ œ์„ค๋ช…
๋ฌธ์ œ์„ค๋ช…2

๐Ÿ“Œ๋ฌธ์ œ์ ‘๊ทผ๋ฐฉ์‹

๋ฌธ์ œ๋ฅผ ๋ณด์ž๋งˆ์ž ๋“ค์—ˆ๋˜ ์ƒ๊ฐ์€ ์›ํ˜• ํ ์ž๋ฃŒ๊ตฌ์กฐ๋ฅผ ์ด์šฉํ•ด์•ผ๊ฒ ๋‹ค์˜€๋‹ค.

์ด์œ ๋Š” ์›์„ ๊ณ„์†ํ•ด์„œ ๋Œ๋ฉด์„œ k๋ฒˆ์งธ ์‚ฌ๋žŒ๋“ค ์ œ์™ธํ•ด๋‚˜๊ฐ€๊ธฐ ๋•Œ๋ฌธ์ด์—ˆ๋‹ค.

ํ•˜์ง€๋งŒ ์›ํ˜•ํ๋กœ ๊ตฌํ˜„ํ•  ๊ฒฝ์šฐ ์ธ๋ฑ์Šค๋ฅผ ๊ณ„์†ํ•ด์„œ ๋ฐ”๊ฟ”์ฃผ์–ด์•ผํ–ˆ๋‹ค.

๋”ฐ๋ผ์„œ ํ๋ฅผ ์ˆœํšŒํ•˜๋ฉฐ ๋ฐฉ๋ฌธํ•œ ๊ฐ’์„ ๋งจ ๋’ค๋กœ ์ด๋™์‹œ์ผœ์ฃผ๋„๋ก ๊ตฌํ˜„ํ–ˆ๋‹ค.

๐Ÿ“Œ๋ฌธ์ œํ’€์ด

์†Œ์Šค์ฝ”๋“œ

import sys
from collections import deque

n, target = map(int, sys.stdin.readline().rstrip().split())
data = deque()
for i in range(1, n+1):
    data.append(i)

def solution(target, data):
    result = []
    i = 1
    while data:
        if i==target:
            result.append(data.popleft())
            i = 1
        else:
            data.append(data.popleft())
            i += 1
    return result

result = solution(target, data)
print('<', end='')
for i in range(len(result)):
    if i == len(result)-1:
        print(result[i], end='')
    else:
        print(result[i], end=', ')
print('>', end='')