我好菜系列——map查找

链接:https://ac.nowcoder.com/acm/contest/931/A
来源:牛客网

DNA序列里只有ACGT四种字母,A和T对应,C和G对应。
俩序列完全对应,就是指它们每一位上的字母一一对应。比如ACG和TGC完全对应
求最多能选出多少对完全对应的DNA序列。(当然一个序列最多被选一次)

第一行一个整数n表示有多少序列。
接下来n行,每行一个长度20的只包含ACGT的字符串,表示序列

map<string,int> 然后就没了;

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#include<iostream>
using namespace std;
int n;
map<string,int > mp;
string a,b;
int ans;
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        cin>>a;
        int len=a.length();
        b="";
        for(int i=0;i<len;i++)
        {
            if(a[i]=='A') b+='T';
            else if(a[i]=='T') b+='A';
            else if(a[i]=='C') b+='G';
            else b+='C';
        }
        if(mp[b])
        {
            ans++;
            mp[b]--;
        }
        else mp[a]++;
    }
    printf("%d",ans);
    
    
    return 0;
}

不要忘了把b清空。。。。。

原文地址:https://www.cnblogs.com/WHFF521/p/11385524.html