728x90
๋ฐ์ํ
https://swexpertacademy.com/main/code/problem/problemDetail.do
SW Expert Academy
SW ํ๋ก๊ทธ๋๋ฐ ์ญ๋ ๊ฐํ์ ๋์์ด ๋๋ ๋ค์ํ ํ์ต ์ปจํ ์ธ ๋ฅผ ํ์ธํ์ธ์!
swexpertacademy.com
์ฝ๋
- input์ ๊ณต๋ฐฑ์ ๊ธฐ์ค์ผ๋ก ์๋ฅธ๋ค (split)
- ์ฒ์๊ณผ ๋์ 2๊ฐ๋ 0์ด๋ฏ๋ก 0,1,2 ์ธ ์ธ๋ฒ์งธ๋ถํฐ ์์, ๋์์ -2๊น์ง ์งํ
- j์์ ์์ 2๊ฐ, ๋ค์ 2๊ฐ ์ค max๋ฅผ ์ฐพ๋๋ค
- 1,2,5,3,4 ๋ผ๊ณ ํ๋ค๋ฉด j๋ 5์ด๊ณ , ์๋ค 2์นธ์ฉ ๊ณต๋ฐฑ์ด ์๋ ์นธ์ ๊ฐฏ์๋ฅผ ์ธ๋ ๊ฒ์ด๋๊น 3์ ๋ค์ 4์ ๋งํ๋ค
- 5 - max > 0 ์ธ์ง ๊ฒ์ฌํ ํ
- 0๋ณด๋ค ํฌ๋ค๋ฉด totalCount์ +๋ฅผ ํ๋ค
for tc in range(10):
listSize = int(input())
inputList = list(map(int, input().split()))
totalCount = 0
for j in range(2, listSize - 2):
maxNum = max(inputList[j - 2], inputList[j - 1], inputList[j + 1], inputList[j + 2])
if inputList[j] - maxNum > 0:
totalCount += inputList[j] - maxNum
print("#{} {}".format(tc+1, totalCount))
format ํจ์
'{์ธ๋ฑ์ค0}, {์ธ๋ฑ์ค1}'.format(๊ฐ0, ๊ฐ1)
๐ ์ฐธ๊ณ ๐
[python] ํ์ด์ฌ format ํจ์ (๋ฌธ์์ด ํฌ๋งคํ ๋ฐฉ๋ฒ 1)
์๋ ํ์ธ์. BlockDMask ์ ๋๋ค. ํ์ด์ฌ์์ ๋ฌธ์์ด ํฌ๋งคํ ๋ฐฉ๋ฒ์ %์ ์์๊ธฐํธ๋ฅผ ์ด์ฉํ ๋ฐฉ๋ฒ, format ํจ์๋ฅผ ์ด์ฉํ ๋ฐฉ๋ฒ, f-string์ ์ด์ฉํ ๋ฐฉ๋ฒ ์ด๋ ๊ฒ ์ธ๊ฐ์ง๊ฐ ์๋ค๊ณ ๋ณผ ์ ์์ต๋๋ค. ์ค๋์ ํ
blockdmask.tistory.com
728x90
๋ฐ์ํ