본문 바로가기
Java/SW Expert Academy

1940. 가랏! RC카!

by GLOWWW 2021. 1. 11.
package oSWExpertAcademy;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class D2_1940 {
    public static void main(String[]args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        try {
            int testCase = Integer.parseInt(br.readLine());
            for(int tc=1; tc<=testCase; tc++) {
                int time = Integer.parseInt(br.readLine());
                int vel = 0;
                int    dis = 0;
                for(int i=0; i<time; i++) {
                    String[] input = br.readLine().split(" ");
                    int command = Integer.parseInt(input[0]);
                    if(command != 0) {
                        int acc = Integer.parseInt(input[1]);
                        if(command == 1) {
                            vel += acc;
                        }else{
                            vel -= acc;
                            if(vel < 0) {
                                vel = 0;
                            }
                        }
                    }
                    dis += vel;
                }
                System.out.println("#"+tc+" "+dis);
            }//testCase for문 
        } catch (NumberFormatException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}

'Java > SW Expert Academy' 카테고리의 다른 글

1288. 새로운 불면증 치료법  (0) 2021.01.12
1928. Base64 Decoder  (0) 2021.01.12
1945. 간단한 소인수분해  (0) 2021.01.11
1946. 간단한 압축 풀기  (0) 2021.01.11
1948. 날짜 계산기  (0) 2021.01.11

댓글