1000/problem/A

传送门:

[http://codeforces.com/contest/1000/problem/A]

题意:

一个比赛颁奖,要准备T-Shirt给获奖者,但有的去年获奖过,衣服尺寸可以不改,有的需要修改,问需要修改几个尺寸

题解:

STL的应用,ma1先统计去年字符串出现的个数,然后输入今年字符串时如果去年不存在这种尺寸就要修改,
最后对比去年今年相同尺寸,如果去年比今年多,那么修改多出的那部分,并把今年这个尺寸数赋值为0,避免重复。

代码:

#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
    map<string,int> ma1,ma2;
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n,i,sum=0;
    string s[105];
    string st;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>s[i];
        ma1[s[i]]++;//统计字符串s[i]出现的个数 
    }
    for(i=1;i<=n;i++)
    {
        cin>>st;
        if(!ma1[st]) sum++;//如果去年不存在这种尺寸就要修改 
        else ma2[st]++;
    }
    for(i=1;i<=n;i++){
        if(ma2[s[i]]-ma1[s[i]]>0) sum+=ma2[s[i]]-ma1[s[i]],ma2[s[i]]=0;
    }
    cout<<sum<<endl;
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/mch5201314/p/9381065.html