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 ...
随机推荐
- jquery的push()
JavaScript push() 方法 JavaScript Array 对象 定义和用法 push() 方法可向数组的末尾添加一个或多个元素,并返回新的长度. 语法 arrayObject.pus ...
- [译]GLUT教程 - 键盘
Lighthouse3d.com >> GLUT Tutorial >> Input >> Keyboard GLUT可以让应用程序自动监测键盘输入,包括普通按键和 ...
- css3 jQuery实现3d搜索框+为空推断
<!DOCTYPE html> <html> <head> <title>css3实现3d搜索框</title> <style> ...
- 【JMeter4.0学习(二)】之搭建openLDAP在windows8.1上的安装配置以及JMeter对LDAP服务器的性能测试脚本开发
目录: 概述 安装测试环境 安装过程 配置启动 配置搭建OpenLDAP 给数据库添加数据 测试查询刚刚插入的数据 客户端介绍 JMeter建立一个扩展LDAP服务器的性能测试脚本开发 附:LDAP学 ...
- laravel学习之路1:认证相关
Laravel中Auth::guard()表示什么意思? Auth::check() 是判断用户是否登录的方法,如果使用的默认用户系统,那这样使用没问题. 但是使用两组用户的话,如何使用各组用户的功能 ...
- CentOS VSCode调试go语言出现:exec: "gcc": executable file not found in PATH
CentOS VSCode调试go语言出现:exec: "gcc": executable file not found in PATH 解决方案: 执行如下命令安装GCC,然后重 ...
- mysql-5.1.73多实例安装启动
一.源码包下载:http://download.softagency.net/MySQL/Downloads/MySQL-5.1/ 二.编译安装 groupadd mysql useradd -r - ...
- iOS 线程管理的学习记录
本文转载至 http://www.2cto.com/kf/201312/265451.html 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 2 ...
- [转]Html position(static、relative、absolute、fixed)
转自:http://blog.csdn.net/topviewers/article/details/21644305 讲解不错,转载备忘. position的四个属性值: 1.relative2.a ...
- Android笔记之使用Glide加载网络图片、下载图片
Glide简介 不想说太多,真的很方便:P)可以节省我不少时间 GitHub地址:https://github.com/bumptech/glide 加载网络图片到ImageView Glide.wi ...