Sicily 1194

题目:

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');
		}
	}
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值