import sys
total = 0
pre_total = 0
for _ in range(10):
mushroom = int(sys.stdin.readline())
pre_total = total # 버섯 먹기 전 단계
total += mushroom # 버섯 먹은 후
if total >= 100:
break
if 100 - pre_total < total - 100:
ans = pre_total
elif 100 - pre_total > total - 100:
ans = total
elif 100 - pre_total == total - 100:
ans = total
print(ans)
🔑 중단점을 잘 설정하는게 포인트!!
버섯을 먹었을때 100점이 넘게 된다면 먹기 전과 비교해서 100점에서 뺐을때 절대값이 더 작은 수를 출력해야 한다.
구글링해보니 abs?
를 쓴 코드가 있던데 나는 모르는 함수라,,, 알아둬야겠다!