Programming/BOJ

[백준/BOJ] 15429 Odd Gnome

he1fire 2020. 9. 18. 03:50
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