👩💻문제 링크
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
3번 제약사항을 지키지 못하면 10개의 test 중 2개를 통과 못한다.
✔️코드
t=int(input())
for tc in range(1,t+1):
n=int(input())
distance=0
arr=[[0]*2 for _ in range(n)]
for i in range(n):
user_input = input().split()
arr[i][0] = int(user_input[0])
if len(user_input)>1:
arr[i][1]=int(user_input[1])
speed = 0
for i in range(n):
#가속
if arr[i][0] == 1:
speed+=arr[i][1]
distance +=speed
#감속
elif arr[i][0] == 2:
if speed!=0:
speed-=arr[i][1]
distance +=speed
#현재속도유지
elif arr[i][0] == 0:
distance +=speed
print(f'#{tc} {distance}')
* split()으로 한 줄씩 입력받았으나 0 하나 있는 줄이 있어서 에러 발생했다.
* user_input() 으로 받아서 크기가 1 이상일 때만 넣어주는 것으로 수정했다.
* 감속 부분에서 현재 speed가 0이면 감속이 되지 않고 speed를 0으로 유지할 수 있게 수정했다.
'코딩테스트 > SW Expert Academy' 카테고리의 다른 글
SWEA.D3 - 1244. [S/W 문제해결 응용] 2일차 - 최대 상금 (0) | 2023.11.01 |
---|---|
SWEA. D2 - 1928. Base64 Decoder Python (0) | 2023.10.28 |
swea D2 - 1946. 간단한 압축 풀기 Python (0) | 2023.10.26 |
SWEA. D2 - 1954. 달팽이 숫자 Python (0) | 2023.10.25 |
SWEA. D2 - 1970. 쉬운 거스름돈 Python (0) | 2023.10.20 |