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 ...
随机推荐
- 脚本学习 game.sh
#!/bin/bash #game_error.sh ]]; then #$#表示参数个数 -lt小于 echo "Usage: game_error.sh time[20170710]&q ...
- Linux 下如何安装 .rpm 文件
执行以下命令安装: rpm -i your-file-name.rpm 详细的可参考: http://os.51cto.com/art/201001/177866.htm
- Android 缓存策略demo
packageinstaller\permission\model\PermissionApps.java /** * Class used to reduce the number of calls ...
- C# 给主程序签名及第三方dll强签名操作
1.给主程序添加签名 添加完成后会自动生成一个*.pfx文件. 2.给第三方程序添加强签名方法: 本文以WAPIWrapperCSharp.dll为例,使用vs Tools下的工具命令 ...
- 【黑金原创教程】【FPGA那些事儿-驱动篇I 】实验八:PS/2模块② — 键盘与组合键
实验八:PS/2模块② — 键盘与组合键 实验七之际,我们学习如何读取PS/2键盘发送过来的通码与断码,不过实验内容也是一键按下然后释放,简单按键行为而已.然而,实验八的实验内容却是学习组合键的按键行 ...
- host.conf 文件
/etc/host.conf文件的作用是设置名称解析时的先后顺序/etc/hosts文件是在使用host解析时,手动的添加的主机记录/etc/relov.conf文件中设置DNS服务器名称以及缺省的域 ...
- 关于hp proliant sl210t服务器raid 1阵列配置
hp proliant sl210t服务器,一般都会带有两个阵列卡 一个服务器自带的Dynamic Smart Array B120i RAID控制器,一个为Slot卡槽上的Smart Array P ...
- react实现全选、取消全选和个别选择
react里面实现全选和取消全选,个别选择等操作,效果如下 代码: import React, {Component} from 'react' export default class Demo e ...
- linux下配置Java_web环境
I安装JDK 1下载jdk*.bin/jdk*.rpm文件 2把安装包copy到安装目录 cp jdk*.bin /www/java 3安装JDK 如果是.bin文件,直接在复制的当前目录执行即可 . ...
- 网络攻防大作业——用python实现wifi破解
实验内容:不借助其他工具,用python暴力破解wifi 实验工具:python3.6+pywifi模块+密码字典 实验环境:Windows7(64bit) 实验思路: 首先搜索附近的wifi,将这些 ...