UVALive 6959 Judging Troubles map应用

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

map<string,int>m;
int a[200000+5];

int main()
{
    int i,n,tot;
    string s;
    while(~scanf("%d",&n))
    {
        m.clear();
        tot=0;
        memset(a,0,sizeof(a));
        for(i=0;i<n;i++)
        {
            cin>>s;
            if(m[s]==0)
            {
                tot++;
                //printf("%d
",tot);
                m[s]=tot;
                a[tot]=1;
            }
            else
            {
                a[m[s]]++;
            }
        }
        int ans=0;
        for(i=0;i<n;i++)
        {
            cin>>s;
            if(m[s]==0) ;
            else if(a[m[s]]!=0)
            {
                ans++;
                a[m[s]]--;
            }
        }
        printf("%d
",ans);
    }
    return 0;
}

版权声明:本文为博主原创文章,未经博主允许不得转载。http://xiang578.top/

原文地址:https://www.cnblogs.com/xryz/p/4847814.html