슈콩

[SWEA] 평범한 숫자 본문

Algorithms/SWEA

[SWEA] 평범한 숫자

shukong 2025. 11. 18. 21:22

 

 

[문제]

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AXhh-H-KwUcDFARQ

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

 

 

 

[소스 코드]

import java.io.*;
import java.util.*;
public class Solution {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;
		int T = Integer.parseInt(br.readLine());
		for(int tc=1;tc<=T;tc++) {
			int result = 0;
			int n = Integer.parseInt(br.readLine());
			int[] num = new int[n];
			st = new StringTokenizer(br.readLine());
			for(int i=0;i<n;i++) {
				num[i] = Integer.parseInt(st.nextToken());
			}
			for(int i=1;i<n-1;i++) {
				int max = num[i];
				int min = num[i];
				min = Math.min(min, Math.min(num[i-1], num[i+1]));
				max = Math.max(max, Math.max(num[i-1], num[i+1]));
				if(num[i]!=min && num[i]!=max) result++;
			}
			System.out.println("#"+tc+" "+result);
		}
	}
}

'Algorithms > SWEA' 카테고리의 다른 글

[SWEA] 일요일  (0) 2025.11.18
[SWEA] 몬스터 사냥  (0) 2025.11.18
[SWEA] 색상환  (0) 2025.11.18
[SWEA] 로봇 언어  (0) 2025.11.18
[SWEA] 승률 비교하기  (0) 2025.11.18