STL 之map解决 Message Flood(原字典树问题)
Time Limit:1500MS Memory Limit:65536KB 64bit IO Format:%lld & %llu
Description
Input
Output
Sample Input
5 3
Inkfish
Henry
Carp
Max
Jericho
Carp
Max
Carp
0
Sample Output
3 方法一:
#include <stdio.h>
#include <string.h>
#include <string>
#include <map>
#include <algorithm>
#include <ctype.h> using namespace std; int main()
{
char str[30];
int len;
int n, m;
int i, j;
map<string,int>ma;
while(scanf("%d", &n)!=EOF)
{ if(n==0)
{
break;
}
scanf("%d%*c", &m );
ma.clear();
for(i=0; i<n; i++)
{
scanf("%s", str );
len = strlen(str );
for(j=0; j<len; j++)
{
str[j] = tolower( str[j] );
}
ma[str]++;
}
for(j=0; j<m; j++)
{
scanf("%s", str );
len = strlen(str);
for(i=0; i<len; i++)
{
str[i]=tolower(str[i]);
}
if(ma[str]>=1)
{n--;
ma[str]=0;
}
} printf("%d\n", n );
}
return 0;
}
方法二:
#include <stdio.h>
#include <string.h>
#include <string>
#include <map>
#include <algorithm>
#include <ctype.h>
using namespace std; int main()
{
char str[30];
int len;
int n, m;
int i, j;
// map<string,int>ma;
while(scanf("%d", &n)!=EOF)
{ if(n==0)
{
break;
}
scanf("%d%*c", &m );
map<string,int>ma;
for(i=0; i<n; i++)
{
scanf("%s", str );
len = strlen(str );
for(j=0; j<len; j++)
{
str[j] = tolower( str[j] );
}
ma[str]++;
}
for(j=0; j<m; j++)
{
scanf("%s", str );
len = strlen(str);
for(i=0; i<len; i++)
{
str[i]=tolower(str[i]);
}
ma.erase(str);
}
printf("%d\n", ma.size() );
}
return 0;
}
STL 之map解决 Message Flood(原字典树问题)的更多相关文章
- STL MAP及字典树在关键字统计中的性能分析
转载请注明出处:http://blog.csdn.net/mxway/article/details/21321541 在搜索引擎在通常会对关键字出现的次数进行统计,这篇文章分析下使用C++ STL中 ...
- poj 2503 Babelfish(Map、Hash、字典树)
题目链接:http://poj.org/bbs?problem_id=2503 思路分析: 题目数据数据量为10^5, 为查找问题,使用Hash或Map等查找树可以解决,也可以使用字典树查找. 代码( ...
- [POJ] #1002# 487-3279 : 桶排序/字典树(Trie树)/快速排序
一. 题目 487-3279 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 274040 Accepted: 48891 ...
- 字典树应用 - poj1002
字典树应用 - poj 1002 Description Businesses like to have memorable telephone numbers. One way to make a ...
- POJ 2418 字典树
题目链接:http://poj.org/problem?id=2418 题意:给定一堆树的名字,现在问你每一棵树[无重复]的出现的百分比,并按树名的字典序输出 思路:最简单的就是用map来写,关于字典 ...
- Go语言字典树定义及实现
// trie 字典树实现 package Algorithm // 字典树节点 type TrieNode struct { children map[interface{}]*TrieNode i ...
- sdut Message Flood(c++ map)
用字典树没过,学习了一下map; 参考博客:http://blog.csdn.net/zhengnanlee/article/details/8962432 AC代码 #include<iost ...
- Message Flood(map)
http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=203#problem/D 以前用字典树做过 #include <strin ...
- stl应用(map)或字典树(有点东西)
M - Violet Snow Gym - 101350M Every year, an elephant qualifies to the Arab Collegiate Programming C ...
随机推荐
- asp.net core mvc视频A:笔记2-4.ActionResult(动作结果,即返回值)
json类型测试 方法一:实例化对象方式 代码 运行结果 方法二:封装方式 代码改动 运行结果 重点视图返回介绍,其他的不做介绍了 项目文件目录及文件添加 代码 运行结果 如果要显示的不是默认视图,可 ...
- MQTT--入门
一.简述 MQTT(Message Queuing Telemetry Transport,消息队列遥测传输协议),是一种基于发布/订阅(publish/subscribe)模式的“轻量级”通讯协议 ...
- 自动清理DataGuard备机日志
>> from zhuhaiqing.info #!/usr/bin/bash #删除DataGuard备机归档日志备份 export ORACLE_HOME=/opt/oracle/pr ...
- HTML_<select>
1.设置select只读不可编辑且select的值可传递 (1) <select onfocus="this.defaultIndex=this.selectedIndex;" ...
- File 的基本操作
package xinhuiji_day07; import java.io.File;import java.io.IOException; public class FileTest { /** ...
- Spring WebSocket Support官方文档+翻译
实时更新技术能够应用在很多场景中,比如在浏览器中聊天.股票报价.状态更新.现场直播.这些需求对时间的延迟性都很敏感,但是我们可以发现他们存在这共有的共性. 标准的HTTP请求,是一次请求对应一次相应. ...
- 嵌入式开发之web服务器---boa移植
近段时间在做ti8148的编解码器又涉及到boa web服务器的移植.在移植到ARM开发板的过程中,遇到很多的问题.原先的自带thttpd 由于功能没有boa完善,比如在ubuntu下面的utf-8编 ...
- MyEclipse中Save could not be completed
在MyEclipse下编程时,保存的时候,假设出现例如以下图所看到的错误: - 刘立 - 707903908的博客" src="http://img0.ph.126.net/9y4 ...
- Bootstrap的js插件之轮播(carousel)
轮播请查看下面演示样例.基本已经涵盖最经常使用的一个轮播 <!DOCTYPE html> <html lang="en"> <head> < ...
- 忘记glassfish密码,那就重置密码呗
方法一:如果现有的 domain 上并没有你所需要的东西,删除现有的 domain,重新创建一个 domain. 找到安装glassfish的目录下的 \bin\asadmin 目录,然后打开asad ...