DNA Consensus String UVA - 1368

题目链接:https://vjudge.net/problem/UVA-1368
DNA Consensus String UVA - 1368_第1张图片
DNA Consensus String UVA - 1368_第2张图片
字符串模拟,可以从字符矩阵中一列一列的查找,列出每列中出现次数最多的字母,拼合起来便是距离最小的DNA。

#include 
#include 
#include 
//A 0 C 1 G 2 T 3
int main() {
    freopen("i.txt","r",stdin);
    int n;
    int arr[1010][4];
    char dna[100][1010];
    int l[1010];
    int t[100][1010];
    scanf("%d",&n);
    while(n-->0) {
        memset(t,0,sizeof(t));
        memset(l,0,sizeof(l));
        memset(arr,0,sizeof(arr));
        int x,y;
        scanf("%d%d",&x,&y);
        for(int i = 0; i < x; i++)
            scanf("%s",dna[i]);
        for(int i = 0; i < y; i++) {
            for(int j = 0; j < x; j++) {
                if(dna[j][i]=='A') {
                    arr[i][0]++;
                    t[j][i] = 0;
                }
                else if(dna[j][i]=='C') {
                    arr[i][1]++;
                    t[j][i] = 1;
                }
                else if(dna[j][i]=='G') {
                    arr[i][2]++;
                    t[j][i] = 2;
                }
                else if(dna[j][i]=='T') {
                    arr[i][3]++;
                    t[j][i] = 3;
                }
            }
        }
        int max = 0, index = 0;
        for(int i = 0; i < y; i++) {
            max = arr[i][0], index = 0;
            for(int j = 0; j < 4; j++) {
                if(arr[i][j] > max) {
                    max = arr[i][j];
                    index = j;
                }
                else if(arr[i][j]==max) {
                    if(j

你可能感兴趣的:(刷题)