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;
    }

  • 相关阅读:
    几种委托的解释
    Python中的编码风格
    Python的循环
    Python中操作文件
    Python的random模块、string模块、time模块、os模块
    Python中的函数
    Python的数据类型
    使用iview Form 的resetFields()在f12下报错
    滚动条的滚动距离
    编程学习之资源
  • 原文地址:https://www.cnblogs.com/danny1221/p/4592719.html
Copyright © 2011-2022 走看看