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 ...
随机推荐
- .net core 2.0小白笔记(一):开发运行环境搭建
小白一枚,有任何不妥之处敬请指教 这里不讨论什么设计模式,什么架构,什么什么,就是入门,简单的入门,虽然能跨平台,但是这里还是在win的环境下进行,不扯的那么远 其实官网文档写的挺不错的了,就是偶尔有 ...
- android dp 和 px 的相互转换
在开发中,可能须要动态设置控件的大小 比如为一个gridview设置宽度: LinearLayout.LayoutParams linearParams2 = (LinearLayout.Layout ...
- 安装java运行环境
1.查看java安装版本 执行命令java -version查看已安装java运行环境信息. 2.下载JDK 到sun官网下载需要的jdk版本,地址为:http://www.oracle.com/te ...
- python char()和ord()
通过help 查看相关函数的帮助文档 >>>help (chr) chr(...) chr(i) -> character Return a string of one cha ...
- css 温故而知新 1px的问题
解决方法1: //border @mixin border($pos, $color) { content: ""; position: absolute; transform-o ...
- STM32 寄存器库和固件库
寄存器和固件库开发的差别和联系 固件库就是函数的集合,固件库函数的作用是向下负责与寄存器直接打交道.向上提供用户函数调用的接口(API). 在 51 的开发中我们经常的作法是直接操作寄存器,比方要控制 ...
- 解读Unity中的CG编写Shader系列3——表面剔除与剪裁模式
在上一个样例中,我们得到了由mesh组件传递的信息经过数学转换至合适的颜色区间以颜色的形式着色到物体上. 这篇文章将要在此基础上研究片段的擦除(discarding fragments)和前面剪裁.后 ...
- oracle快速复制表数据
方法一: 只复制表结构: create table table_name_new as select * from table_name_old where 1=2; 然后: alter sessio ...
- NIM游戏策略
NIM取子游戏是由两个人面对若干堆硬币(或石子,或..)进行的游戏,游戏由两个人进行,设有k>=1堆硬币,各堆含有n1,n2,n3,n4.....,nk个硬币,游戏的目的就是选取最后剩下的硬币. ...
- 【Python+selenium Wendriver API】之鼠标悬停事件
# encoding=utf-8 from selenium import webdriver from selenium.webdriver.common.action_chains import ...