반응형
코딩하기 전 생각하기
/*
8개의 숫자를 입력받아 벡터에 저장한다.
조건문으로 벡터을 판별하여 ascending, descending, mixed 중 하나를 출력한다.
벡터가 1 2 3 4 5 6 7 8 이라면 “ascending”을 출력한다.
벡터가 8 7 6 5 4 3 2 1 이라면 “descending”을 출력한다.
둘 다 아니라면 “mixed”를 출력한다.
*/
코드
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> arr(8);
vector<int> ascending = {1, 2, 3, 4, 5, 6, 7, 8};
vector<int> descending = {8, 7, 6, 5, 4, 3, 2, 1};
for ( int i = 0; i < 8; i++ ) {
cin >> arr[i];
}
if ( arr == ascending ) {
cout << "ascending" << endl;
}
else if ( arr == descending ) {
cout << "descending" << endl;
}
else {
cout << "mixed" << endl;
}
}
느낀점
is_sorted 함수와 같은 알고리즘을 구현해야될 것 같기도 한데.. 풀 문제는 많고 시간은 없으니 간단하게 하고 넘어가도록 하겠다.
(주의) 기록용으로 작성한 글입니다. 코드가 허접하거나 알고리즘의 효율이 낮을 수 있습니다.
댓글 환영합니다!
반응형
'Algorithm > Baekjoon' 카테고리의 다른 글
[백준/BOJ] 8958번 - OX퀴즈 (C++) (0) | 2021.07.06 |
---|---|
[백준/BOJ] 4659번 - 비밀번호 발음하기 (파이썬) (0) | 2021.07.06 |
[백준/BOJ] 1159번 - 농구 경기 (C++) (0) | 2021.07.06 |
[백준/BOJ] 2799번 - 블라인드 (C++) (2) | 2021.07.06 |
[백준/BOJ] 4344번 - 평균은 넘겠지 (C++) (0) | 2021.07.06 |
댓글