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 ...
随机推荐
- vim 基本常用设置
1. :set number 设置行号 2. :set relativenumber 设置相对行号 3. :set hlsearch 设置搜索高亮 4. :set noh 关闭搜索高亮 ...
- IOS 10 微信 ajax readystate=0 status=0 解决方法
最近做了一个 基于微信访问的网页系统 发现IOS10.2.1 版本 访问的时候 AJAX报错,安卓和IOS11.4.1 没有这样的问题. 通过Fiddler抓包发现,AJAX请求时 报错信息为 {& ...
- Apollo-open-capacity-platform 微服务能力开发平台 (转)
来自大佬的apollo整合微服务的教程:欢迎大家点评和star,链接如下:https://gitee.com/owenwangwen/open-capacity-platform 官方demo链接:h ...
- vi编辑器命令大全
>> from zhuhaiqing.info
- KSTORE日常工作遇到问题总结
1.csv导入kstore命令语句 oimpexp -F "E:/127.csv" -S KSTORE -T "T_BUSDATA" -d 1 -z -B 7 ...
- 【Mac系统】istatmenus6.20下载以及激活
下载地址:https://pan.baidu.com/s/1-2-yw2NnOlGJ46D536t5uQ iStat Menus 的激活密码: Email: 982092332@qq.com SN: ...
- redis php 执行命令时,单引号和双引号的区别。
#今天遇到一个坑爹的问题,写成单引号就不行,被原样输出了. /** *判断key是否存在 */ function exists_key($key){ return $this->cmd('EXI ...
- PHP里的socket_recv方法解释
以前一直经为PHP里没有低级的socket帧接收函数,看来是没看仔细,不过那些说明也太少了,(更令人气的里在英文版说明里的例子下有一句话:这个程序不能运行,因为没用listen函数,但在中文版里却没了 ...
- 在express项目中使用redis
在express项目中使用redis 准备工作 安装redis 安装redis桌面管理工具:Redis Desktop Manager 项目中安装redis:npm install redis 开始使 ...
- html5-框架网站
1.html5+:http://www.html5plus.org/ 2.hbuilder:http://www.dcloud.io/ 3.mui:http://dev.dcloud.net.cn/m ...