SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
www.swexpertacademy.com
#include <iostream>
#include <ios>
using namespace std;
int T, N, command, speed;
int currentSpeed, currentDistance;
void getDistance();
int main() {
cin.tie(0); ios::sync_with_stdio(0);
cin >> T;
for (int testCase = 1; testCase <= T; testCase++) {
currentSpeed = 0, currentDistance = 0;
cin >> N;
for (int i = 0; i < N; i++) {
cin >> command;
if (command == 0) { // 유지
currentDistance += currentSpeed;
}
else {
cin >> speed;
getDistance();
}
}
cout << '#' << testCase << ' ' << currentDistance << "\n";
}
return 0;
}
void getDistance() {
if (command == 1) { // 가속
currentSpeed += speed;
}
else { // 감속
if (currentSpeed < speed) currentSpeed = 0;
else currentSpeed -= speed;
}
currentDistance += currentSpeed;
}
'알고리즘 > SWEA' 카테고리의 다른 글
[SWEA] 1954. 달팽이 숫자 (0) | 2019.04.21 |
---|---|
[SWEA] 1926. 간단한 369게임 (0) | 2019.04.17 |
[SWEA] 2005. 파스칼의 삼각형 (0) | 2019.04.17 |
[SWEA] 1961. 숫자 배열 회전 (0) | 2019.04.16 |
[SWEA] 2001. 파리 퇴치 (0) | 2019.04.16 |
댓글