[BOJ/백준] 4470 – 줄 번호

문제 번호

문제를 해결하다

각 테스트 케이스에 대해 3개의 숫자가 입력되고 3개의 숫자가 오름차순 또는 내림차순으로 정렬되는지 여부가 결정됩니다.

올바른 응답 코드

C++

#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>

using namespace std;

#define fast ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0)
#define ll long long

int main() {
    fast;
    int t;
    cin >> t;
    cout << "Gnomes:\n";
    while(t--){
        vector <int> lst(3);
        for(int i = 0; i < 3; i++) cin >> lst(i);
        if ((lst(1) - lst(0)) * (lst(2) - lst(1)) > 0) cout << "Ordered\n";
        else cout << "Unordered\n";
    }
}

파이썬

print("Gnomes:")
for _ in range(int(input())) :
    lst = list(map(int, input().split()))
    result = True
    if (lst(2) - lst(1) >= 0 and lst(1) - lst(0) >= 0) or (lst(2) - lst(1) < 0 and lst(1) - lst(0) < 0) : print("Ordered")
    else : print("Unordered")