블로그 언저리인 무언가
[백준/BOJ] 15429 Odd Gnome 본문
728x90
문제: 15429 Odd Gnome
15429번: Odd Gnome
The input starts with an integer n, where 1 ≤ n ≤ 100, representing the number of gnome groups. Each of the n following lines contains one group of gnomes, starting with an integer g, where 3 ≤ g ≤ 1 000, representing the number of gnomes in that g
www.acmicpc.net
오름차순 수열이 주어지고, 그중 오름차순을 따르지 않는 한 숫자를 찾아
그 위치를 출력하면 되는 문제이다.
배열을 순회하면서 자신은 오름차순에 위배되면서
앞, 뒤 숫자는 규칙을 지키는 위치를 찾아 출력하였다.
Code
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
ll T;
cin >> T;
while (T--){
ll N, arr[1005];
cin >> N;
for (int i=0;i<N;i++)
cin >> arr[i];
for (int i=1;i<N-1;i++){
if (arr[i-1]<=arr[i+1] && (arr[i-1]>=arr[i] || arr[i]>=arr[i+1])){
cout << i+1 << "\n";
}
}
}
return 0;
}
728x90
'Programming > BOJ' 카테고리의 다른 글
[백준/BOJ] 5525 IOIOI (0) | 2020.09.19 |
---|---|
[백준/BOJ] 1780 종이의 개수 (0) | 2020.09.19 |
[백준/BOJ] 1213 팰린드롬 만들기 (0) | 2020.09.18 |
[백준/BOJ] 1531 투명 (0) | 2020.09.18 |
[백준/BOJ] 9715 면적 구하기 (0) | 2020.09.18 |