๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
๐Ÿ’œ ์ฝ”๋”ฉํ…Œ์ŠคํŠธ/๐Ÿ’œSWEA

1206. [S/W ๋ฌธ์ œํ•ด๊ฒฐ ๊ธฐ๋ณธ] 1์ผ์ฐจ - View (Python)

by eyes from es 2023. 11. 16.
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
๋ฐ˜์‘ํ˜•