SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
import java.util.Scanner;
import java.io.FileInputStream;
class Solution
{
public static void main(String args[]) throws Exception
{
Scanner sc = new Scanner(System.in);
int T;
T=sc.nextInt();
for(int test_case = 1; test_case <= T; test_case++)
{
int N = sc.nextInt();
int distance=0;
int speed=0;
for(int i=0; i<N; i++){
int a = sc.nextInt();
int b=0;
if(a!=0)
b= sc.nextInt();
if(a==0)
distance += speed;
else if(a==1){
speed += b;
distance +=speed;
}
else if(a==2){
speed -=b;
if(speed<0)
speed=0;
distance +=speed;
}
}
System.out.println("#" + test_case + " " + distance);
}
}
}
속도 가속도 거리 따로 설정해주면 되고, 가속도가 음수가 되는 경우가 없다고 했으니 그 부분만 잘 걸어주면 된다.
'SWEA' 카테고리의 다른 글
[SWEA] 수도 요금 경쟁 (0) | 2024.10.10 |
---|---|
[SWEA] 새로운 불면증 치료법 (1) | 2024.10.10 |
[SWEA] 간단한 압축 풀기 (0) | 2024.10.06 |
[SWEA] 간단한 소인수분해 (1) | 2024.10.06 |
[SWEA] 날짜 계산기 (0) | 2024.10.04 |