상세 컨텐츠

본문 제목

[SWEA] #11736 평범한 숫자.python(파이썬)

문제풀이/SWEA

by jer0618 2021. 7. 21. 22:04

본문

문제 링크 / 출처

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

 

SW Expert Academy

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

swexpertacademy.com

 

풀이

pi 가 최솟값도, 최댓값도 아닌 수이므로,

 

수열에서 양 옆에 있는 두 숫자 사이의 수임을 판정하여 평범한 숫자의 개수를 계산하였다.

 

코드

T = int(input())

for t in range(T):
    N = int(input())
    lst = [int(i) for i in input().split()]
    cnt = 0
    for p in range(1, N - 1):
        if (lst[p-1] < lst[p] < lst[p+1]) or (lst[p+1] < lst[p] < lst[p-1]):
            cnt += 1
    print(f'#{t + 1} {cnt}')
반응형

관련글 더보기