题目:
Input
There are multiple test cases. In each case, at the first line there are two numbers n and m (1<=n, m<=20000), which is the number of friends and the number of messages he has received. And then there are n lines of alphabetic strings (the length of each will be less than 10), indicating the names of Merlin’s friends, one per line. After that there are m lines of alphabetic strings, which are the names of message senders.
The input is terminated by n=0.
Output
For each case, print one integer in one line which indicates the number of left friends he must send.
Sample Input
Inkfish
Henry
Carp
Max
Jericho
Carp
Max
Carp
0
Sample Output
3
WA了一次,百度了一下,发现原来题目有说过大小写不敏感,所以多加了一个全部改为小写的函数
然后用STL的map直接做,在cplusplus.com找了map的用法,因为一直不是很熟每次都上去找。
以下是解法:
// Copyright <lijiancheng> [2014]
// Sicily 1194
#include <string.h>
#include <iostream>
#include <map>
using namespace std;
void to_lower(string &s);
int main() {
int n, m;
string name;
map<string, int> maps;
while (cin >> n && n != 0) {
cin >> m;
maps.clear();
for (int i = 0; i < n; i++) {
cin >> name;
to_lower(name);
maps[name] = 0;
}
for (int i = 0; i < m; i++) {
cin >> name;
to_lower(name);
map<string, int>::iterator it = maps.find(name);
if ( it != maps.end()) {
maps.erase(it);
}
}
cout << maps.size() << endl;
}
return 0;
}
void to_lower(string &s){
int len=s.length();
for(int i=0;i<len;i++){
if(s[i]>='A'&&s[i]<='Z'){
s[i]='a'+(s[i]-'A');
}
}
}