2455. 지능형 기차

이윤설·2023년 3월 9일
0

https://www.acmicpc.net/problem/2455

내가 쓴 코드

people = 0

A,B = map(int, input().split())
C,D = map(int, input().split())
E,F = map(int, input().split())
G,H = map(int, input().split())

result1 = A + B
result2 = result1 - C + D
result3 = result2 - E + F
result4 = result3 - G + H

list = []
list.append(result1)
list.append(result2)
list.append(result3)
list.append(result4)

list.sort(reverse=True)
print(list)
print(list[0])

정답

list = []
result = 0

for i in range(4):
    a, b = map(int, input().split())   # a와 b 입력 4번씩 받기
    
    result = result - a + b
    list.append(result)
        
print(max(list))

오답노트

정답이 필요 이상으로 길다.
1.for 반복문을 통해 input()을 여러번 받을 수 있다.
2.for 반복문 이하에서 append를 함으로서 8개 모두 리스트에 넣을 수 있다.
3.max(list)를 통해 그 중 가장 큰 값을 불러온다.

profile
화려한 외면이 아닌 단단한 내면

0개의 댓글