[๋ฐฑ์ค-1138] ํ ์ค๋ก ์๊ธฐ / Python
๐ Problem Solving/Baekjoon
https://www.acmicpc.net/problem/1138
import sys
input = sys.stdin.readline
n = int(input())
line = list(map(int, input().split()))
answer = [0] * n
for i in range(1, n + 1):
temp = line[i - 1]
cnt = 0
for j in range(n):
if temp == cnt and answer[j] == 0:
answer[j] = i
break
elif answer[j] == 0:
cnt += 1
print(*answer)
ํด์ค
answer์ ๊ฐ์ด ๋ค์ด๊ฐ ์ธ๋ฑ์ค ์ ๋ถ๋ถ์ 0๋ค์ ๋ชจ๋ ๊ทธ ๊ฐ๋ณด๋ค ํฐ ๊ฐ์ด ๋ค์ด๊ฐ๊ฒ ๋๋ค.
cnt๋ answer๋ฅผ ์์์๋ถํฐ ํ์ํ์ ๋ 0์ ๊ฐ์์ด๋ค.
line[i-1]์ด cnt์ ๊ฐ์ ๋ ๋ฐ๋ก ๋ค์ answer ์ธ๋ฑ์ค์ i๋ฅผ ๋ฃ์ด์ค๋ค. ์ด๋ฏธ answer์ ํด๋น ์ธ๋ฑ์ค์ ๊ฐ์ด ๋ค์ด๊ฐ ๊ฒฝ์ฐ๋ผ๋ฉด ๊ณ์ ๋ฆฌ์คํธ๋ฅผ ๋์ 0์ธ ๋ถ๋ถ์ i๋ฅผ ๋ฃ์ด์ค๋ค.
'๐ Problem Solving > Baekjoon' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[๋ฐฑ์ค-2251] ๋ฌผํต / Python (0) | 2021.07.01 |
---|---|
[๋ฐฑ์ค-17413] ๋จ์ด ๋ค์ง๊ธฐ 2 / Python (1) | 2021.06.28 |
[๋ฐฑ์ค-1051] ์ซ์ ์ ์ฌ๊ฐํ / Python (0) | 2021.06.21 |
[๋ฐฑ์ค-5567] ๊ฒฐํผ์ / Python (0) | 2021.06.21 |
[๋ฐฑ์ค-3085] ์ฌํ ๊ฒ์ / Python (0) | 2021.06.21 |