deep_lee 2022. 11. 16. 16:22

https://swexpertacademy.com/main/code/problem/problemDetail.do?problemLevel=3&contestProbId=AXhh-H-KwUcDFARQ&categoryId=AXhh-H-KwUcDFARQ&categoryType=CODE&problemTitle=&orderBy=PASS_RATE&selectCodeLang=ALL&select-1=3&pageSize=10&pageIndex=7 

 

SW Expert Academy

SW ν”„λ‘œκ·Έλž˜λ° μ—­λŸ‰ 강화에 도움이 λ˜λŠ” λ‹€μ–‘ν•œ ν•™μŠ΅ 컨텐츠λ₯Ό ν™•μΈν•˜μ„Έμš”!

swexpertacademy.com

 


κ·Έλƒ₯ 총 3개 수λ₯Ό κΈ°μ€€μœΌλ‘œ, κ°€μš΄λ°μžˆλŠ” μˆ˜κ°€ 3개 수 μ€‘μ—μ„œ κ°€μž₯ μž‘μ€κ°’λ„ μ•„λ‹ˆκ³ , 큰 값도 μ•„λ‹λ•Œ ν‰λ²”ν•œ 숫자 인 것

 

 

 

import java.util.Scanner;
import java.util.*;

public class Solution {
    public static void main(String[] args) {
        Scanner kb = new Scanner(System.in);
        int T = kb.nextInt();
        for (int t = 1; t <= T; t++) {
            int n=kb.nextInt();
            int[] arr=new int[n];
            for(int i=0; i<n; i++) arr[i]=kb.nextInt();

            int cnt=0;
            for(int i=1; i<n-1; i++){
            	// iκ°€ i-1보닀 크고 i+1보닀 μž‘μ€ 경우 or iκ°€ i-1보닀 μž‘κ³  i+1보닀 큰 경우
                if(arr[i]>arr[i-1]&&arr[i]<arr[i+1]||arr[i-1]>arr[i]&&arr[i]>arr[i+1])
                    cnt++;
            }
            System.out.println("#"+t+" "+cnt);
        }
    }
}