Message Flood(map)
http://acm.sdut.edu.cn:8080/vjudge/contest/view.action?cid=203#problem/D
以前用字典树做过
#include <string.h>
#include <stdio.h>
#include <string>
#include <map>
using namespace std; int main()
{
char a[];
int n,m,sum,l;
while(scanf("%d",&n)!=EOF&&n!=)
{
sum=;
scanf("%d",&m);
map<string,int>q;
q.clear();
for(int i=; i<n; i++)
{
scanf("%s",a);
l=strlen(a);
for(int j=; j<l; j++)
a[j]=tolower(a[j]);//将字符转换成小写字符
q[a]++;
}
while(m--)
{
scanf("%s",a);
l=strlen(a);
for(int i=;i<l;i++)
a[i]=tolower(a[i]);
if(q.count(a)>)
{
sum++;
q.erase(q.find(a));
}
}
printf("%d\n",n-sum); }
return ;
}
第一次做的方法
#include<stdio.h>
#include<iostream>
#include<map>
#include<stdlib.h>
#include<string.h> using namespace std;
char a[][];
int main()
{
int n,m,l;
char b[];
map<string,int>q;
while(scanf("%d",&n)!=EOF&&n!=)
{
q.clear();
scanf("%d",&m);
getchar();
for(int i=;i<n;i++)
{
gets(a[i]);
l=strlen(a[i]);
for(int j=;j<l;j++)
{
if(a[i][j]>='A'&&a[i][j]<='Z')
a[i][j]=a[i][j]+;
}
q[a[i]]++;
}
for(int i=;i<=m;i++)
{
gets(b);
l=strlen(b);
for(int i=;i<l;i++)
{
if(b[i]>='A'&&b[i]<='Z')
b[i]=b[i]+;
}
q[b]--;
}
int sum=;
for(int i=;i<n;i++)
{
if(q[a[i]]>=)
sum++;
}
printf("%d\n",sum);
}
return ;
}
大神的代码
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio> #include <set> using namespace std; int main()
{
int n,m,i,j,len;
char s[];
while(scanf("%d",&n)!=EOF&&n)
{
set<string>mp;//声明set容器
set<string>::iterator it;//声明set迭代器
scanf("%d",&m);
getchar();
for(i=; i<n; i++)
{
gets(s);
len=strlen(s);
for(j=; j<len; j++)
{
s[j]=towlower(s[j]);
}
mp.insert(s);//向set里加入一个元素
}
for(i=; i<m; i++)
{
gets(s);
len=strlen(s);
for(j=; j<len; j++)
{
s[j]=towlower(s[j]);
}
if(mp.count(s))//判断容器里是否存在该元素
mp.erase(s);//如果容器里存在该元素,则删除
}
printf("%d\n",mp.size());//输出容器内剩余元素个数
}
return ;
}
Message Flood(map)的更多相关文章
- STL 之map解决 Message Flood(原字典树问题)
Message Flood Time ...
- Message Flood
Message Flood Time Limit: 1500MS Memory limit: 65536K 题目描述 Well, how do you feel about mobile phone? ...
- Sicily 1194. Message Flood
题目地址:1194. Message Flood 思路: 不区分大小写,先全部转化为小写,用stl提供的函数做会很方便. 具体代码如下: #include <iostream> #incl ...
- sdut Message Flood(c++ map)
用字典树没过,学习了一下map; 参考博客:http://blog.csdn.net/zhengnanlee/article/details/8962432 AC代码 #include<iost ...
- SDUT1500 Message Flood
以前做过的用的字典树,可是貌似现在再用超内存....求解释... 问了LYN用的map函数做的,又去小小的学了map函数.... http://wenku.baidu.com/view/0b08cec ...
- oj1500(Message Flood)字典树
大意:输入几个字符串,然后再输入几个字符串,看第一次输入的字符串有多少没有在后面的字符串中出现(后输入的字符串不一定出现在之前的字符串中) #include <stdio.h> #incl ...
- 图层损坏 E/ArcGIS﹕ The map or layer has been destroyed or recycled. 资源未释放
看到论坛上有个网友和我一样的问题: The map or layer has been destroyed or recyled t Hello, I have a problem when the ...
- proto3 中的 map 类型
.proto syntax = "proto3"; option optimize_for = SPEED; message TestStruct { map<int32,s ...
- SDUT 1500-Message Flood(set)
Message Flood Time Limit: 1500ms Memory limit: 65536K 有疑问?点这里^_^ 题目描写叙述 Well, how do you feel abo ...
随机推荐
- 【大数据系列】hadoop单机模式安装
一.添加用户和用户组 adduser hadoop 将hadoop用户添加进sudo用户组 sudo usermod -G sudo hadoop 或者 visudo 二.安装jdk 具体操作参考:c ...
- nginx(一)----ubuntu14.04下安装nginx
/** * lihaibo * 文章内容都是根据自己工作情况实践得出. *如有错误,请指正 *转载请注明出处 */ 此文章中用到的软件下载地址: 链接: http://pan.baidu.com/s/ ...
- VMware ESXI5.5 Memories limits resolved soluation.
在使用VMware ESXI5.5 的时候提示内存限制了,在网上找的了解决方案: 如下文: 1. Boot from VMware ESXi 5.5; 2. wait "Welcome to ...
- for,for-each,for-in,for-of,map的比较
参考: 全面解析JavaScript里的循环方法之forEach,for-in,for-of Iterator 和 for...of 循环 JavaScript Array 对象 常规for for循 ...
- 关于C#泛型作用的简单说明
泛型:即通过参数化类型来实现在同一份代码上操作多种数据类型.泛型编程是一种编程范式,它利用“参数化类型”将类型抽象化,从而实现更为灵活的复用. C#泛型的作用概述 C#泛型赋予了代码更强的类型安全,更 ...
- win7下桌面右键一直转圈圈的解决方法
今天公司同事的电脑,在进入win7系统后,桌面右键一直转圈圈,找我解决这个问题. 经过我观察,他电脑只是在桌面上右键有此现象,在其他地方并无此现象. 因此可以得出结论,此现象很可能与桌面右键有关,经上 ...
- 通过Adb 查看当前正在运行的Activity.
extends:http://www.cnblogs.com/tt_mc/p/4269833.html adb shell dumpsys activity activities | sed -En ...
- 第一个maven项目
1.新建maven project 注意:勾上create a new simple project 2.填写相关信息, Grounp id为大项目名字,Artifact id为小项目的名字.注意:P ...
- elasticsearch的索引自动清理及自定义清理
近发现elasticsearch近期索引文件大的吓人,清理了下之前的索引文件,发现服务器性能大大的减轻了一半,想一直保留近一个月的索引文件,但是又不想每个月手动清楚,在此写了一个小脚本 查询索引: c ...
- Docker 安装Centos,Tomcat,Jdk等相关的自定义(Dockerfile)镜像
一.安装Centos镜像 这里Centos 安装 国内daocloud网站提供的官方镜像 docker pull daocloud.io/library/centos:latest 利用docker ...