【习题 3-7 UVA - 1368 】DNA Consensus String

【链接】 我是链接,点我呀:)
【题意】

在这里输入题意

【题解】

枚举每一位字母是什么。 从小到大枚举。 然后计算每一位的总贡献是多少。 取最小的那个输出。

【代码】

#include <bits/stdc++.h>
using namespace std;

const int M = 50;
const int N = 1e3;
const char b[] = {'A','C','G','T'};

int T,n,m;
char s[M+10][N+100];

int main(){
	#ifdef LOCAL_DEFINE
	    freopen("rush_in.txt", "rt", stdin);
	#endif
	scanf("%d",&T);
	while (T--){
	 	scanf("%d%d",&n,&m);
	 	for (int i = 1;i <= n;i++) scanf("%s",s[i]+1);
		string ans1 = "";int ans2 = 0;
		for (int j = 1;j <= m;j++){
			int temp = 0x3f3f3f3f;char temp1;
			for (int jj = 0;jj < 4;jj++){
				char key = b[jj];
				int cur = 0;
			 	for (int i = 1;i <= n;i++){
			 		cur += (s[i][j]!=key); 	
			 	}
			 	if (cur < temp){
			 	 	temp1 = key;
			 	 	temp = cur;
			 	}
		 	}
		 	ans1+=temp1;ans2+=temp;
		}
		cout << ans1 <<endl;
		cout << ans2 << endl;
	}

	return 0;
}
posted @ 2017-11-08 10:55  AWCXV  阅读(142)  评论(0编辑  收藏  举报