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 ...
随机推荐
- Python在mysql中进行操作是十分容易和简洁的
首先声明一下,我用的是Windows系统! 1.在Python中对mysql数据库进行操作首先要导入pymysql模块,默认情况下,Python中是没有安装这个模块的, 可以在Windows的命令行中 ...
- 列式存储hbase系统架构学习
一.Hbase简介 HBase是一个开源的非关系型分布式数据库(NoSQL),它参考了谷歌的BigTable建模,实现的编程语言为 Java.它是Apache软件基金会的Hadoop项目的一部分,运行 ...
- 转载:C/C++关于string.h头文件和string类
学习C语言时,用字符串的函数例如stpcpy().strcat().strcmp()等,要包含头文件string.h 学习C++后,C++有字符串的标准类string,string类也有很多方法,用s ...
- 配置Mac漂亮的Shell--Iterm2+OhMyZSH+Agnoster
安装包管理器 首先当然是解决包管理的问题,Mac下面是Homebrew的天下了 /usr/bin/ruby -e "$(curl -fsSL https://raw.githubuserco ...
- CentOS 配置Rails开发环境
1 安装mysql yum install -y mysql mysql-server 启动mysql $ /etc/init.d/mysqld start 设置root密码,删除test数据库等 / ...
- FAX modem和传真协议简介
FAX就是传真,传真通信是使用传真机,借助公用通信网或其他通信线路传送图片,文字等信息,并在接收方获得发送原件系统的副本的一种通信方式.传真通信是现代图像通信的重要组成部分,它是目前采用公用电话网传送 ...
- 【BZOJ3456】城市规划 多项式求逆
[BZOJ3456]城市规划 Description 刚刚解决完电力网络的问题, 阿狸又被领导的任务给难住了. 刚才说过, 阿狸的国家有n个城市, 现在国家需要在某些城市对之间建立一些贸易路线, 使得 ...
- 【BZOJ3328】PYXFIB 数论+矩阵乘法
[BZOJ3328]PYXFIB Description Input 第一行一个正整数,表示数据组数据 ,接下来T行每行三个正整数N,K,P Output T行,每行输出一个整数,表示结果 Sampl ...
- python pytest测试框架介绍四----pytest-html插件html带错误截图及失败重测机制
一.html报告错误截图 这次介绍pytest第三方插件pytest-html 这里不介绍怎么使用,因为怎么使用网上已经很多了,这里给个地址给大家参考,pytest-html生成html报告 今天在这 ...
- Android sd卡log日志
import android.os.Environment; import android.util.Log; import java.io.File; import java.io.FileOutp ...