CodeForces 1000A Codehorses T-shirts(STL map、思维)

https://codeforces.com/problemset/problem/1000/A

 

 

题意:

有n个人,给出每个人的衣服的尺码,现在,将这n件衣服的尺码换成另外的n种尺码,如果有尺码一样的衣服,则不需要换,问,最少需要更换几件衣服。

思路:

map记录一下每种尺码的衣服出现的次数,然后对新尺码进行一一比对,如果新尺码的数量大于原有的,则说明要更换数量为二者差值的衣服。

代码: 

 1 #include <stdio.h>
 2 #include <string.h>
 3 #include <iostream>
 4 #include <string>
 5 #include <math.h>
 6 #include <algorithm>
 7 #include <vector>
 8 #include <stack>
 9 #include <queue>
10 #include <set>
11 #include <map>
12 #include <math.h>
13 const int INF=0x3f3f3f3f;
14 typedef long long LL;
15 const int mod=1e9+7;
16 const int maxn=1e5+10;
17 using namespace std;
18 
19 int main()
20 {
21     int n;
22     cin>>n;
23     map<string,int> mp1,mp2;
24     map<string,int>::iterator it;
25     string str;
26     int num=0;
27     for(int i=1;i<=n;i++)
28     {
29         cin>>str;
30         mp1[str]++;
31     }
32     for(int i=1;i<=n;i++)
33     {
34         cin>>str;
35         mp2[str]++;
36     }
37     for(it=mp2.begin();it!=mp2.end();it++)
38     {
39         if(it->second>mp1[it->first])
40             num+=it->second-mp1[it->first];
41     }
42     printf("%d
",num);
43     return 0;
44 }

原文地址:https://www.cnblogs.com/jiamian/p/11620288.html