DNA Consensus String

来源:互联网 发布:网络霸屏 编辑:程序博客网 时间:2024/06/06 08:39

UVa1368

这道题我以为是要求一个串到所有串的距离最小,不过好像可以扩展,但是我好像写不出。

#include <stdio.h>#include <string.h>const int maxn = 1005;char str[maxn][maxn], ch[5] = "ACGT", ans[maxn];int cnt[5];int main ( ){    int T, n, m, value;    scanf ( "%d", &T );    while ( T -- )    {        value = 0;        scanf ( "%d%d", &n, &m );        for ( int i = 0; i < n; i ++ )            scanf ( "%s", str[i] );        for ( int j = 0; j < m; j ++ )        {            memset ( cnt, 0, sizeof ( cnt ) );            for ( int i = 0; i < n; i ++ )            {                for ( int k = 0; k < 4; k ++ )                    if ( str[i][j] == ch[k] )                        cnt[k] ++;            }            int mx = 0, mi = 0;            for ( int i = 0; i < 4; i ++ )                if ( mx < cnt[i] )  //ch存放字典序                {                    mx = cnt[i];                    mi = i;                }            value = value+n-mx;            ans[j] = ch[mi];        }        ans[m] = '\0';        printf ( "%s\n%d\n", ans, value );    }    return 0;}


0 0