말랑한 하루

[SW Expert Academy] 6730 장애물 경주 난이도 [C++] 본문

문제풀이/SWexpert Academy

[SW Expert Academy] 6730 장애물 경주 난이도 [C++]

지수는말랑이 2021. 1. 20. 01:22
반응형

[ 핵심풀이 ]

[ 핵심소스 ]

[ C++ ]

#include <iostream>
#include <algorithm>
#pragma warning(disable:4996)

using namespace std;

#define endl "\n"
#define INF 2147483647
#define MAX 100

int block;
int obstacle[MAX];
int main() {
    int tc;
    cin >> tc;
    for (int t = 1; t <= tc; t++) {
        int high = 0, low = 0;
        cin >> block;
        for (int i = 0; i < block; i++)
            cin >> obstacle[i];
        for (int i = 0; i < block - 1; i++) {
            int stay = obstacle[i] - obstacle[i + 1];
            if (stay < 0)
                high = high > abs(stay) ? high : abs(stay);
            else
                low = low > stay ? low : stay;
        }
        cout << "#" << t << " " << high << " " << low << endl;
    }
}
반응형
Comments