sdut Message Flood

D -  Message Flood

Time Limit: 1500 MS      Memory Limit: 65536 KB      64bit IO Format: %lld & %llu

Description

Well, how do you feel about mobile phone? Your answer would probably be something like that "It's so convenient and benefits people a lot". However, If you ask Merlin this question on the New Year's Eve, he will definitely answer "What a trouble! I have to keep my fingers moving on the phone the whole night, because I have so many greeting message to send!" Yes, Merlin has such a long name list of his friends, and he would like to send a greeting message to each of them. What's worse, Merlin has another long name list of senders that have sent message to him, and he doesn't want to send another message to bother them Merlin is so polite that he always replies each message he receives immediately). So, before he begins to send message, he needs to figure to how many friends are left to be sent. Please write a program to help him. Here is something that you should note. First, Merlin's friend list is not ordered, and each name is alphabetic strings and case insensitive. These names are guaranteed to be not duplicated. Second, some senders may send more than one message to Merlin, therefore the sender list may be duplicated. Third, Merlin is known by so many people, that's why some message senders are even not included in his friend list.

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

5 3
Inkfish
Henry
Carp
Max
Jericho
Carp
Max
Carp
0

Sample Output

STL真心方便啊。这题分别用了map和set做了一下。注意这个题有个坑点,就是不区分大小写。。。。。

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <queue>
#include <map>
#include<algorithm>

using namespace std;
int main()
{
	map<string,int>mp;
	map<string,int>::iterator iter;
	int n, m, i, len, j;
	char s[30];
	while(scanf("%d",&n)!=EOF&&n)
	{
		scanf("%d",&m);
		getchar();
		mp.clear();//如果在外面定义的话要注意清空。
		for(i=0;i<n;i++)
		{
			gets(s);
			len=strlen(s);
			for(j=0;j<len;j++)
			{
				s[j]=tolower(s[j]);//tolower函数的意义是将大写字母全换成小写字母
			}
			mp[s]++;
		}
		for(i=0;i<m;i++)
		{
			gets(s);
			len=strlen(s);
			for(j=0;j<len;j++)
			{
				s[j]=tolower(s[j]);
			}
			mp.erase(s);//erase函数的意义是在该容器中删除该元素
		}
		printf("%d\n",mp.size());//直接用size函数输出容器内元素的个数,不用遍历计数。
	}
	return 0;
}

set代码:

#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <ctype.h>
#include <queue>
#include <map>
#include <set>
#include<algorithm>

using namespace std;
int main()
{
	int n, m, i, len, j;
	char s[30];
	while(scanf("%d",&n)!=EOF&&n)
	{
		scanf("%d",&m);
		getchar();
		set<string>mp;//声明set容器
		set<string>::iterator iter;//声明set迭代器
		for(i=0; i<n; i++)
		{
			gets(s);
			len=strlen(s);
			for(j=0; j<len; j++)
			{
				s[j]=tolower(s[j]);
			}
			mp.insert(s);//向set里加入一个元素
		}
		for(i=0; i<m; i++)
		{
			gets(s);
			len=strlen(s);
			for(j=0; j<len; j++)
			{
				s[j]=tolower(s[j]);
			}
			if(mp.count(s))//判断容器里是否存在该元素
				mp.erase(s);//如果容器里存在该元素,则删除
		}
		printf("%d\n",mp.size());//直接输出容器剩余元素个数。
	}
	return 0;
}


### 关于Python与SDUT的相关信息 #### Python在SDUT的应用 山东理工大学(Shandong University of Technology, SDUT)在其ACM在线评测系统中提供了大量基于Python的编程题目,这些题目涵盖了基础算法、数据结构以及面向对象编程等多个方面。通过解决这些问题,学生可以提升自己的编程能力并熟悉Python语言的核心特性[^1]。 #### 提供的具体实例分析 以一道典型的输入输出练习为例,展示了如何利用`while`循环读取多组测试数据直到遇到特定终止条件为止。此方法非常适合处理批量计算场景下的逻辑实现: ```python while True: s = input().split() if int(s[0]) == 0 and int(s[1]) == 0: break print(int(s[0]) + int(s[1])) ``` 上述代码片段实现了连续求两数之和的功能,并在两个输入均为零时结束程序运行。这体现了Python简洁优雅的特点及其强大的字符串操作功能。 #### 面向对象实践案例 另一个例子涉及定义矩形类来完成几何图形属性的操作,如下所示: ```python class Rect: def __init__(self, x, y): if x <= 0 or y <= 0: self.x, self.y = 0, 0 else: self.x, self.y = x, y def length1(self): return self.x * 4 def area1(self): return self.x ** 2 def length2(self): return (self.x + self.y) * 2 def area2(self): return self.x * self.y try: l = list(map(int, input().split())) if len(l) == 1: a = Rect(l[0], 1) print(a.x, a.x, a.length1(), a.area1()) elif len(l) == 2: a = Rect(l[0], l[1]) print(a.x, a.y, a.length2(), a.area2()) except: pass ``` 该脚本不仅巩固了基本算术运算的知识点,还引入了异常捕获机制确保程序健壮性[^3]。 #### 数学运算综合应用 对于简单的数值型任务如三数加总、相乘及均值计算,则有以下解决方案展示精确控制浮点显示的方式[^4]: ```python a, b, c = map(int, input().split()) x = a + b + c y = a * b * c z = x / 3 print(f"{x} {y} {z:.2f}") ``` 这段代码清晰明了地完成了指定格式化输出的要求,同时运用到了现代f-string技术简化模板替换过程。 ### 总结 综上所述,无论是初学者还是有一定经验的学习者都能从SDUT所提供的资源中学到实用技能。它覆盖范围广泛,既包括简单概念也包含复杂理论的实际运用情况介绍。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值