๐ฉ๐ปโ๐ป๋ฌธ์ ๋งํฌ
[๋ฐฑ์ค 2309] ์ผ๊ณฑ ๋์์ด (Python)
โ๏ธIdea Sketch
2021-07-29
1. ๋ธ๋ฃจํธ ํฌ์ค(brute force) = ๋ฌด์ํ ํ = ์์ ํ์ ์๊ณ ๋ฆฌ์ฆ
2. i๋ 0๋ถํฐ 8๋ฒ์งธ๊น์ง ํ์, j๋ i+1๋ถํฐ 9๋ฒ์งธ๊น์ง ํ์
for i in range(8):
for j in range(i+1, 9):
3. ์ด์ค ๋ฐ๋ณต๋ฌธ ์ข ๋ฃํ๊ธฐ
โ๏ธ์์ค์ฝ๋
2021-07-29
๋ฐฉ๋ฒ 1. ํจ์ ์ ์ธ ํ return, 80ms ํต๊ณผ
height = sorted([int(input()) for _ in range(9)])
total = sum(height)
def solution():
for i in range(8):
for j in range(i+1, 9):
if total - height[i] - height[j] == 100:
return i, j
i, j = solution()
for k in range(9):
if k == i or k == j:
continue
print(height[k])
๋ฐฉ๋ฒ 2. sys.exit(0) ์ฌ์ฉ, 76ms ํต๊ณผ
import sys
height = sorted([int(input()) for _ in range(9)])
total = sum(height)
for i in range(8):
for j in range(i+1, 9):
if total - height[i] - height[j] == 100:
for k in range(9):
if k == i or k == j:
continue
print(height[k])
sys.exit(0)