본문 바로가기
알고리즘/SWEA

1940. 가랏! RC카! D2

by 모두의 향연 2022. 2. 15.
728x90
반응형
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.StringReader;
import java.util.StringTokenizer;
 
public class Solution {
    public static void main(String[] args) throws NumberFormatException, IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuffer sb = new StringBuffer();
        StringTokenizer st;
 
        int T = Integer.parseInt(br.readLine());
        int sum=0;
        for (int tc = 1; tc <= T; tc++) {
            sb.append("#").append(tc).append(" ");
 
            sum=0;
            int speed = 0;
            int distance=0;
            int N = Integer.parseInt(br.readLine());// N값
            for (int i = 0; i < N; i++) {
                st = new StringTokenizer(br.readLine());
                int command = Integer.parseInt(st.nextToken());// 0(현재속도유지) 1(가속) 2(감속)
 
                switch (command) {
                case 0:// 현재속도 유지
                    break;
                case 1:// 가속
                    speed = Integer.parseInt(st.nextToken());
                    sum+=speed;
                    break;
                case 2:// 감속
                    speed = Integer.parseInt(st.nextToken());
                    if(sum<speed) {
                        speed=0;
                    }
                    sum-=speed;
                    break;
                }
                distance+=sum;
            }
            sb.append(distance).append("\n");
        }
        System.out.println(sb);
    }
}
cs

거 속 시 생각하면 절대 안된다..

그냥 하라는대로 풀면 풀리는 그런 문제 ㅎ

 

*거리는 계속 늘어야지 줄순없잖아

728x90
반응형