:: ADVANCE ::

84일차 1. cryption 본문

Algorithm/일일알고리즘

84일차 1. cryption

KSJ14 2014. 9. 30. 17:43
반응형
http://183.106.113.109/30stair/cryption/cryption.php?pname=cryption

 

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
#include <iostream>
using namespace std;
 
int num[10];
int n, cnt;
 
int checknum(int chnum, int e)
{
    int check, ten = 1, flag = 0;
    for(int i = 0; i < e; i++)    {
        check = (chnum/ten) %10;
        for(int j = 0; j < n; j++)    {
            if(check == num[j])    {
                flag = 1;
                j = n;
            }
        }
        if(flag == 0)    {
            return -1;
        }
        flag = 0;
        ten *= 10;
    }
    return 1;
}        
 
int func(void)
{
    long long number3 = 0, ten = 1, result, result1, result2;
    for(int i = 0; i < n; i++)    {
        for(int j = 0; j < n; j++)    {
            for(int k = 0; k < n; k++)    {
                number3 = num[i]*100 + num[j]*10 + num[k];
                for(int x = 0; x < n; x++)    {
                    result1 = number3 * num[x];
 
                    if( result1 > 999 || checknum(result1, 3) < 0)    {
                        continue;
                    }
 
                    for(int y = 0; y < n; y++)    {
                        result2 = number3 * num[y];
 
                        if( result2 > 999 || checknum(result2, 3) < 0)    {
                            continue;
                        }
                        result = result2*10 + result1;
        
                        if( result < 10000 && checknum(result, 4) > 0) {
                            cnt++;
                        }
                    }
                }
            }
        }
    }
    return cnt;
}
int main(void)
{
    cin >> n;
    
    for(int i = 0; i < n; i++)    {
        cin >> num[i];
    }
 
    cout << func() << endl;
 
    return 0;
}
반응형

'Algorithm > 일일알고리즘' 카테고리의 다른 글

90일차 1. sprime  (0) 2014.10.08
91일차 1. eratosthenes  (0) 2014.10.07
86일차 1. ncpc_event  (0) 2014.10.02
85일차 1. ladder  (0) 2014.10.02
83일차 1. cantoring  (0) 2014.09.30
Comments