SW ExpertAcademy/D2
1940. 가랏! RC카!
Programmer.
2018. 12. 1. 00:33
1940. 가랏! RC카!
풀이 방법
<코드>
#include<iostream> #include<cstring> using namespace std; int main(int argc, char** argv) { int test_case; int T; cin >> T; for (test_case = 1; test_case <= T; ++test_case) { int command{ 0 }; std::cin >> command; int commandType{ 0 }; int value{ 0 }; int currentVecocity{ 0 }; int distance{ 0 }; for (int i = 0; i < command; i++) { std::cin >> commandType; if (commandType != 0) std::cin >> value; switch (commandType) { case 0: break; case 1: currentVecocity += value; break; case 2: if (currentVecocity - value < 0) currentVecocity = 0; else currentVecocity -= value; break; } distance += currentVecocity; } std::cout << "#" << test_case << " " << distance << "\n"; } return 0;//정상종료시 반드시 0을 리턴해야합니다. }