본문 바로가기
알고리즘/그리디 알고리즘

1969 DNA

by tryotto 2019. 7. 1.
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
#include <stdio.h>
 
int check[55][10= { 0 };
int dist[1005][55= { 0 };
 
int main() {
    int n, m;
    scanf("%d %d"&n, &m);
    
    for (int i = 0; i < n; i++) {
        char str[55= { 0 };
        scanf("%s"&str);
        getchar();
 
        for (int j = 0; j < m; j++) {
            switch(str[j]) {
            case 'A':
                check[j][1]++;
                dist[i][j] = 1;
                break;
            case 'T':
                dist[i][j] = 4;
                check[j][4]++;
                break;
            case 'G':
                dist[i][j] = 3;
                check[j][3]++;
                break;
            case 'C':
                dist[i][j] = 2;
                check[j][2]++;
                break;                
            }
        }
    }
 
    int maxA[55= { 0 };
    for (int i = 0; i < m; i++) {
        int max = 0, alpha = 0;
        for (int j = 1; j <= 4; j++) {
            if (max < check[i][j]) {
                max = check[i][j];
                alpha = j;
            }
        }
        maxA[i] = alpha;
 
        switch (alpha) {
        case 1printf("A");
            break;
        case 2printf("C");
            break;
        case 3printf("G");
            break;
        case 4printf("T");
            break;
        }
    }
 
    int rst = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
            if (maxA[j] != dist[i][j])
                rst++;
        }
    }
    printf("\n%d", rst);
}
cs


'알고리즘 > 그리디 알고리즘' 카테고리의 다른 글

1781 컵라면  (0) 2019.08.29
1543 문서정리  (0) 2019.07.01
2873 롤러코스터 (재풀이 필요)  (0) 2019.06.30
9576 책 나눠주기  (0) 2019.06.29
2188 축사 배정 (이분 매칭)  (0) 2019.06.29