UVA - 1368 ​​​​​​​DNA Consensus String

DNA Consensus String

 UVA - 1368 

题目传送门

解决方法:寻找每列中出现最多的字母。

AC代码

#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <bitset>
#include <set>
#include <utility>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define inf 0x3f3f3f3f
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define lep(i,l,r) for(int i=l;i>=r;i--)
#define ms(arr) memset(arr,0,sizeof(arr))
//priority_queue<int,vector<int> ,greater<int> >q;
const int maxn = (int)1e5 + 5;
const ll mod = 1e9+7;
char mapp[55][1050];
char arr[1200];
map<char,int> mt;
int main() 
{
    #ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    #endif
    //freopen("out.txt", "w", stdout);
    ios::sync_with_stdio(0),cin.tie(0);
    int T;
    scanf("%d",&T);
    while(T--)
    {
    	int n,m;
    	ms(arr);
    	scanf("%d %d",&n,&m);
    	rep(i,1,n) {
    		scanf("%s",mapp[i]+1);
    	}
    	int ans=0;
    	rep(j,1,m) {
    		int maxl=0;
    		for(char t='A';t<='Z';t++)
				mt[t]=0; 		
    		rep(i,1,n) {
    			mt[mapp[i][j]]++;
    		}
    		for(char t='A';t<='Z';t++)
    		{
    			if(mt[t]>maxl)
    			{
    				arr[j]=t;
    				maxl=mt[t];
    			}
    			ans+=mt[t];
    		}
    		ans-=maxl;
    	}
    	rep(j,1,m) {
    		printf("%c",arr[j]);
    	}
    	printf("\n");
    	printf("%d\n",ans);
    }
    return 0;
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值