SYCOJ2140祝福短信

题目—祝福短信 (shiyancang.cn)

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 map<string,bool> ans;
 4 int n,m,res;
 5 string low(string s)
 6 {
 7     for(int i=0;i<s.size();i++) s[i]=tolower(s[i]);
 8     return s;
 9 }
10 int main()
11 {
12     string st;
13     scanf("%d%d",&n,&m);
14     int p=n;
15     while(n--)
16     {
17         cin>>st;st=low(st);
18         if(ans[st]==1) p--;
19         ans[st]=1;
20         //另外一种写法
21         //赋0,会自动去重,然后只要遍历,看有几个是0即可 
22     }
23     while(m--)
24     {
25         cin>>st;st=low(st);
26         //if(ans[st]==0) p--,ans[st]=1; 有可能会有不是朋友的默认初始化0
27         //数据里有重复朋友,所有不能用总量减去,总量不一定是真实的总量 
28         if(ans[st]==1) ans[st]=0,p--; 
29     }
30     cout<<p<<endl;
31     return 0;
32 } 

题目会有很多的陷阱,比如可能会有重复.

这题是一个很简单的stl,对其计数即可,去掉重复的可以直接减,或者可以直接通过选取为0的点,因为map的第一关键字自动去重.那么重复朋友已经被去掉了.

 

posted @ 2021-06-05 21:26  mofan552  阅读(31)  评论(0)    收藏  举报