본문 바로가기
Computer Science

배열의 분할

by OKOK 2019. 2. 12.

1. 오케이

2. 이정도는 무난하쥬

3. 오름차순, 내림차순 


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include <stdio.h>
 
const int ASC = 1, DESC = -1, MAXN = 10;
int a[MAXN];
int tc, T, n;
 
int solve(void)
{
    int ans = 1;
    int order = 0;
    for (int i = 1; i < n; ++i)
    {
        if (a[i - 1!= a[i]) // 다르면
        {
            if (order == 0// 시작 포인트
            {
                if (a[i - 1> a[i]) order = DESC; // 내림
                else order = ASC; // 오름차순
            }
            else
            {
                if (a[i - 1> a[i] && order == ASC || // 오름이거나, 내림이면
                    a[i - 1< a[i] && order == DESC)
                {
                    order = 0;
                    ++ans;
                }
            }
        }
    }
    return ans;
}
 
int main(void)
{
    freopen("input.txt""r", stdin);
    for (tc = scanf("%d"&T); tc <= T; ++tc)
    {
        scanf("%d"&n);
        for (int i = 0; i < n; ++i) scanf("%d", a + i);
        printf("#%d %d\n", tc, solve());
    }
    return 0;
}
cs

 


'Computer Science' 카테고리의 다른 글

초콜릿과 건포도  (0) 2019.02.12
석찬이의 받아쓰기  (0) 2019.02.12
재미있는 오셀로 게임  (0) 2019.02.12
러시아 국기 같은 깃발  (0) 2019.02.12
늘어지는 소리 만들기  (0) 2019.02.12

댓글