DNA Consensus String UVA - 1368

#include <iostream>
#include <string>

using namespace std;

int m, n;  // 行数,列数
string strs[50];  // 存储每一行
int num = 0;
string result;  // 存储结果

void Counts();

int main() {
	int T;  // 循环次数
	cin >> T;
	while (T--) {
		cin >> m >> n;
		while (getchar() != '\n')
			continue;
		for (int i = 0; i < m; i++)
			getline(cin, strs[i]);
		Counts();
		cout << result << endl;
		cout << num << endl;
	}
	return 0;
}

void Counts() {
	char c;
	int A = 0, C = 0, G = 0, T = 0;
	int max = 0;
	num = 0;
	result.clear();
	for (int j = 0; j < n; j++) {
		for (int i = 0; i < m; i++) {
			if (strs[i][j] == 'A')
				A++;
			else if (strs[i][j] == 'C')
				C++;
			else if (strs[i][j] == 'G')
				G++;
			else
				T++;
		}
		if (A > max) {
			max = A;
			c = 'A';
		}
		if (C > max) {
			max = C;
			c = 'C';
		}
		if (G > max) {
			max = G;
			c = 'G';
		}
		if (T > max) {
			max = T;
			c = 'T';
		}
		num += m - max;
		result += c;
		A = C = G = T = max = 0;
	}
}

猜你喜欢

转载自blog.csdn.net/malazhuzai/article/details/83572840