본문 바로가기
Computer Science

단순 2진 암호코드

by OKOK 2019. 1. 24.

1. 오케이

2. 점점 익숙해지고 있음

3. 비트로 계산하는 것도 ㅇㅋ

3. [][] 2차원 배열의 경우, *로 값을 받고, ** 로 가져오기 가능함 


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
#include <stdio.h>
 
char code[50][101];
int password[8];
 
int decode(int);
 
int main()
{
    freopen("input.txt""r", stdin);
    int T, test_case;
    int N, M;
    int start_line;
    int sum;
    int tmp;
    int res;
    int cnt;
    int i, j;
 
    scanf("%d"&test_case);
    for (T = 1; T <= test_case; ++T)
    {
        sum = 0;
        start_line = -1;
        cnt = 0;
        scanf("%d %d"&N, &M);
        for (i = 0; i < N; ++i)
        {
            scanf("%s"*(code + i));
            if (start_line < 0)
            {
                for (j = 0; j < M - 49++j)
                {
                    if ((*(*(code + i) + j) == '1')) // 1인 숫자를 찾기
                    {
                        start_line = i;
                        break;
                    }
                }
            }
        }
 
        for (i = 0; i < (M - 8&& (cnt < 8); ++i) // i가 열 idx를 저장
        {
            tmp = 0;
            for (j = i; j < i + 7++j) // 7칸 이동함
                tmp = (tmp << 1+ (*(*(code + start_line) + j) - '0'); // 해시처럼 본인만의 tmp를 만든 후  -> 예제 문제 힌트 얻음
            res = decode(tmp); // decode 함
            if (res != -1)
            {
                password[cnt++= res;
                i += 6// 7칸 이동후에 검사를 진행함
            }
            else if ((res == -1&& (cnt > 0))
            {
                i -= (7*cnt); // 잘 못된 코드를 검사하고 있음, 다시 돌아가서 검사를 진행함
                cnt = 0;
            }
        }
        if (((password[0+ password[2+ password[4+ password[6]) * 3 + password[1+ password[3+ password[5+ password[7]) % 10 == 0)
        {
            for (i = 0; i < 8++i)
                sum += password[i];
        }
        printf("#%d %d\n", T, sum);
    }
    return 0;
}
 
int decode(int src)
{
    switch (src)
    {
    case 13return 0;
    case 25return 1;
    case 19return 2;
    case 61return 3;
    case 35return 4;
    case 49return 5;
    case 47return 6;
    case 59return 7;
    case 55return 8;
    case 11return 9;
    defaultreturn -1;
    }
}
cs

 


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

최대 상금  (0) 2019.01.24
암호코드 스캔  (0) 2019.01.24
Contact  (0) 2019.01.24
비밀번호  (0) 2019.01.24
사칙연산 유효성 검사  (0) 2019.01.24

댓글