zoukankan      html  css  js  c++  java
  • UVa1368/ZOJ3132 DNA Consensus String

    #include <stdio.h>
    #include <string.h>

    int main()
    {
        int a[4][1000]; // A/C/G/T在每列中出现的次数
        char c, x;
        char bas[4] = { 'A', 'C', 'G', 'T' };
        int T, m, n, i, j, k, dist;
        scanf("%d", &T);
        while (T--)
        {
            scanf("%d %d ", &m, &n);
            memset(a, 0, sizeof(a));
            for (i = 0; i < m; ++i)
            {
                for (j = 0; j < n; ++j)
                {
                    c = getchar();
                    if (c == 'A')
                        ++a[0][j];
                    else if (c == 'C')
                        ++a[1][j];
                    else if (c == 'G')
                        ++a[2][j];
                    else
                        ++a[3][j];
                }
                getchar();
            }

            dist = 0;
            for (j = 0; j < n; ++j)
            {
                k = -1;
                for (i = 0; i < 4; ++i)
                {
                    if (a[i][j] > k)
                    {
                        k = a[i][j];
                        x = bas[i];
                    }
                }
                for (i = 0; i < 4; ++i)
                {
                    if (bas[i] != x)
                        dist += a[i][j];
                }
                putchar(x);
            }
            printf(" %d ", dist);
        }

        return 0;
    }

  • 相关阅读:
    Sizzle源码分析 (一)
    VueJS 数据驱动和依赖追踪分析
    使用 nvm 来管理nodejs版本 。
    在node中使用 ES6
    mongoDB & Nodejs 访问mongoDB (二)
    mongoDB & Nodejs 访问mongoDB (一)
    Javascript原型链和原型继承
    Javascript 闭包与高阶函数 ( 二 )
    SDOI2019&十二省联考 游记
    Luogu-3648 [APIO2014]序列分割
  • 原文地址:https://www.cnblogs.com/danny1221/p/4592719.html
Copyright © 2011-2022 走看看