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 ...
随机推荐
- <转>机器学习系列(9)_机器学习算法一览(附Python和R代码)
转自http://blog.csdn.net/han_xiaoyang/article/details/51191386 – 谷歌的无人车和机器人得到了很多关注,但我们真正的未来却在于能够使电脑变得更 ...
- Qt封装百度人脸识别+图像识别
AI技术的发展在最近几年如火如荼,工资待遇也是水涨船高,应用的前景也是非常广阔,去年火起来的人脸识别,今年全国遍地开花,之前封装了下face++的人脸识别等接口,今年看了下百度的AI,还免费了,效果也 ...
- Webpack 备忘录
Webpack 属于在项目中配置一次就很少改动的那种工具,但这样就导致新项目再配置 Webpack 时会有些生疏,所以将 Webpack 核心概念及常用配置记录如下. 1)核心概念 Webpack 4 ...
- 转载>>ASCII、UTF8、Uncicode编码下的中英文字符大小
原地址:http://www.tracefact.net/CSharp-Programming/Network-Programming-Part2.aspx ASCII.UTF8.Uncicode编码 ...
- elementUI Message 独立引入的用法
同理,Alert,MessageBox, Notification, 也是这样引入 单组件单独引用: import { Message } from 'element-ui'; export defa ...
- Sencha Touch 扩展集合
https://market.sencha.com/extensions http://try.sencha.com/touch/2.1.0/ http://www.mitchellsimoens.c ...
- 关于Thinkphp访问不正常的问题
最近遇见了个蹩脚的问题,我放在服务器的项目(thinkphp框架)只能访问默认路径内容,不管你url怎么写的,他就访问默认那个文件.. 对于有强迫症的我来说实在是欺人太甚!!! 于是乎我就抓耳挠腮了. ...
- java.lang.ClassNotFoundException: hudson.remoting.Launcher
jenkins构建失败,错误信息如下: [yjp-dev-po-hrsync] $ "C:\Program Files\Java\jdk1.8.0_121/bin/java" -c ...
- 最简单,最实用的数据库CHM文档生成工具——DBCHM
DBCHM支持SqlServer/MySql/Oracle/PostgreSQL等数据库的表列批注维护管理. DBCHM有以下几个功能 表,列的批注可以编辑保存到数据库. 表,列的批注支持通过pdm文 ...
- 2018C语言第三次作业
要求一 2.struct sk{int a; char *str)}*p; p->str++ 中的++ 加向? ++加向srt的地址. 要求二 题目1-计算平均成绩 1.设计思路 (1)主要 ...