sdut1500 Message Flood

文章介绍了一位名叫梅林的人,在新年期间因需要发送大量祝福消息而遇到的困扰。通过程序帮助梅林计算剩余需要发送祝福的人数,解决手机消息发送问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一开始用的暴搜各种超时啊。。。时间复杂度On*m大约得4亿必须超时啊。。。。后来看了LZN同学的mp瞬间感觉好简单啊。。可惜菜鸟C++不精通啊。。。以后要好好的学习啊。。。。

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.

输入

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.

输出

For each case, print one integer in one line which indicates the number of left friends he must send.

示例输入

5 3
Inkfish
Henry
Carp
Max
Jericho
Carp
Max
Carp
0

示例输出

3
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <stdio.h>

using namespace std;

int main()
{
    int n, m;
    while(~scanf("%d",&n) && n != 0)
    {
        scanf("%d",&m);
        map<string, int> mp;
        string name;
        for(int i = 0; i < n; i++)
        {
            cin>>name;
            transform(name.begin(), name.end(), name.begin(), ::tolower);
            mp[name] = 1;
        }
        for(int i = 0; i < m; i++)
        {
            cin>>name;
            transform(name.begin(), name.end(), name.begin(), ::tolower);
            if(mp[name] == 1)
            {
                n--;
                mp[name] = 0;
            }
        }
        printf("%d\n",n);
    }
    return 0;
}


### SDUT PTA 编程题解与在线评测系统使用说明 #### 关于SDUT PTA在线评测系统的概述 SDUT PTA(Programming Teaching Assistant)是一个面向学生学习编程的在线评测平台,主要用于支持山东理工大学计算机科学及相关专业的课程教学。该平台提供了丰富的练习题目以及自动化的测试机制,帮助学生巩固所学的知识并提升实际编程能力[^1]。 #### 如何使用SDUT PTA在线评测系统? 以下是关于如何有效利用SDUT PTA进行编程训练的关键要点: 1. **注册账号** 学生需通过学校指定的方式完成账户注册,并登录到对应的班级页面参与作业提交和考试活动。 2. **熟悉界面布局** 登录后可以看到左侧导航栏包含了“我的作业”、“公开试题”等功能模块;右侧则显示具体任务列表及其状态信息(未做/已交/得分情况)。点击某道题目可以查看其详细描述、样例输入输出以及其他提示内容[^2]。 3. **编写代码并调试** 对于像“计算1到n的和”的简单问题,可以直接采用如下C语言实现方式来解决: ```c #include<stdio.h> int main(){ int n, sum=0; scanf("%d",&n); for(int i=1;i<=n;i++) { sum +=i; } printf("%d\n",sum); return 0; } ``` 此段代码实现了基本的功能需求——读取用户输入的一个正整数值`n`,并通过循环累加得到最终的结果输出。 4. **提交解决方案** 完成本地开发环境中的编码工作之后,在网页端找到对应位置上传源文件或者直接粘贴文本框内的代码片段即可发起评测请求。注意遵循每道题目的特殊约束条件比如时间复杂度限制等规定。 5. **分析反馈结果** 提交完成后会迅速获得运行状况报告,如果存在错误,则应仔细阅读报错消息重新审视自己的逻辑是否存在漏洞再尝试修正直至完全正确为止。 #### 常见问题解答 对于初学者来说可能会遇到一些困惑之处,下面列举几个典型场景供参考: - 如果发现即使按照标准答案复制也得不到满分怎么办?可能是因为忽略了某些边界情形处理或者是格式化方面的小失误所致。 - 当面对较复杂的算法类挑战不知道从哪里下手时建议先梳理清楚思路画流程图辅助理解后再动手实践。 - 还有就是保持耐心多试几次不要轻易放弃因为每一次失败都是成长的机会! ###
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值