728x90
4589번: Gnome Sequencing
In the book All Creatures of Mythology, gnomes are kind, bearded creatures, while goblins tend to be bossy and simple-minded. The goblins like to harass the gnomes by making them line up in groups of three, ordered by the length of their beards. The gnomes
www.acmicpc.net
문제 풀이
테스트 케이스마다 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";
}
}
python
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")
728x90
'Algorithm > PS' 카테고리의 다른 글
[BOJ/백준] 5341 - Pyramids [C++/python] (0) | 2023.03.02 |
---|---|
[BOJ/백준] 5300 - Fill the Rowboats! [C++/python] (0) | 2023.03.02 |
[BOJ/백준] 4470 - 줄 번호 [C++/python] (0) | 2023.03.01 |
[BOJ/백준] 3765 - Celebrity jeopardy [C++/python] (0) | 2023.03.01 |
[C++, python] BOJ, 백준 3733 - Shares (0) | 2023.02.28 |