习题3-7(uva-1368)

#include <iostream>
#include <vector>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <cstring>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <numeric>
#include <chrono>
#include <ctime>
#include <cmath>
#include <cctype>
#include <string>
#include <cstdio>
#include <iomanip>


#include <thread>
#include <mutex>
#include <condition_variable>
#include <functional>
#include <iterator>
using namespace std;
int r, c;
int matrix[1005][4] = { 0 };
char input[1005];


int GetIndex(char in) {
	switch (in)
	{
	case 'A':return 0;
	case 'C':return 1;
	case 'G':return 2;
	case 'T':return 3;
	default:
		break;
	}
	return -1;
}
char GetChar(int id) {
	switch (id)
	{
	case 0:return 'A';
	case 1:return 'C';
	case 2:return 'G';
	case 3:return 'T';
	default:
		break;
	}
	return 'Z';
}
void CulCount() {
	int  temp = 0;
	for (int i = 0; i < c; ++i) {
		temp = GetIndex(input[i]);
		for (int j = 0; j < 4; ++j) {
			if(temp == j) continue;
			matrix[i][j]++;
		}
	}
}
int main()
{
	int t,id;
	cin >> t;
	while (t--) {
		int nCount = 0;
		memset(matrix, 0, sizeof(matrix));
		cin >> r >> c;
		cin.get();
		for (int i = 0; i < r; ++i) {
			fgets(input, 1005, stdin);
			CulCount();
		}

		for (int i = 0; i < c; ++i) {
			id = 0;
			for (int j = 1; j < 4; ++j) {
				if (matrix[i][j] < matrix[i][id]) id = j;
			}
			nCount += matrix[i][id];
			input[i] = GetChar(id);
		}
		input[c] = '\0';
		cout << input << endl;
		cout << nCount << endl;
	}
	return 0;
}
©️2020 CSDN 皮肤主题: 技术黑板 设计师:CSDN官方博客 返回首页