Deep_Dev

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);
        }
    }
}