본문 바로가기
Computer Science

정곤이의 단조 증가하는 수

by OKOK 2019. 1. 31.

1. 정곤의의 단조증가 하는 수

2. 오케이

3. 소팅?

4. 퀵 소팅 오케이

5. 보고 이해, 응용 가능

6. 무엇을 어디에 가져다 쓸지

7. 자료구조는 어떻게 만들지가 중요함 


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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include <stdio.h>
 
#define MAX 10
int INPUT[MAX];
 
void qsort(int *arr, int left, int right);
int solve(int cnt);
int isValid(int value);
 
int main(void)
{
    freopen("input.txt""r", stdin);
    int test_case;
    int T;
 
    setbuf(stdout, NULL);
    scanf("%d"&T);
 
    for (test_case = 1; test_case <= T; ++test_case)
    {
        int cnt;
        scanf("%d"&cnt);
        for (int i = 0; i < cnt; i++) {
            scanf("%d"&INPUT[i]);
        }
        qsort(INPUT, 0, cnt);
 
        int answer = solve(cnt);
        printf("#%d %d\n", test_case, answer);
    }
    return 0;
}
 
int solve(int cnt)
{
    int ret = -1;
    for (int i = 0; i < cnt - 1; i++) {
        for (int j = i + 1; j < cnt; j++)
        {
            int mul = INPUT[i] * INPUT[j];
 
            if (isValid(mul)) { // 유효성 검사는 10디짓으로 검사, 최댓값을 찾기
                if (ret < mul) {
                    ret = mul;
                    break;
                }
            }
            if (mul < ret) break;
        }
    }
    return ret;
}
 
int isValid(int value)
{
    int ret = 1;
 
    int preVal = 10;
    while (value >= 10) {
        int curVal = value % 10// 뒤에자리 수
        if (curVal > preVal) { // 앞 자리수와 뒷 자리수 비교
            ret = 0;
            break;
        }
        preVal = curVal;
        value /= 10;
    }
 
    if (ret) {
        if (value > preVal) ret = 0;
    }
    return ret;
}
 
void qsort(int *arr, int left, int right) {
    int i = left;
    int j = right;
    int temp;
    int pivot = arr[(left + right) / 2];
 
    while (i <= j) {
        while (arr[i] > pivot) ++i;
        while (arr[j] < pivot) --j;
 
        if (i <= j) {
            temp = arr[i];
            arr[i] = arr[j];
            arr[j] = temp;
            i++;
            j--;
        }
    }
    if (j > left) qsort(arr, left, j);
    if (i < right) qsort(arr, i, right);
}
cs

 


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

문자열 변경하기  (0) 2019.01.31
중호와 세 소수  (0) 2019.01.31
삼성시의 버스 노선  (0) 2019.01.31
기차 사이의 파리  (0) 2019.01.30
금속막대  (0) 2019.01.28

댓글