HDU 1247 Hat's Words (map+string)
Hat’s Words
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 10993 Accepted Submission(s): 3944
#include<iostream>
#include<cstdio>
#include<string>
#include<map>
using namespace std; map<string,int> M;
string str[]; int main()
{
//freopen("in.txt", "r", stdin);
int k = -;
while(cin>>str[++k])
M[str[k]] = ;
for(int i=; i<=k; i++)
{
int len= str[i].size()-;
for(int j=; j<len; j++)
{
string s1(str[i], , j);
string s2(str[i], j);
if(M[s1]==&&M[s2]==)
{
cout<<str[i]<<endl;
break;
}
}
}
return ;
}
本题技巧: string s1(str[i], 0, j);把str[i]中的0~j的字符赋给s1. string s2(str[i], j)把str[i]中的j~末尾的字符赋给s2.
HDU 1247 Hat's Words (map+string)的更多相关文章
- HDU 1247 Hat’s Words(map,STL,字符处理,string运用)
题目 用map写超便捷 也可以用字典树来写 我以前是用map的: #include<stdio.h> #include<string.h> #include<algori ...
- HDU 1247 Hat’s Words (字典树 && map)
分析:一開始是用递归做的,没做出来.于是就换了如今的数组.即,把每个输入的字符串都存入二维数组中,然后创建字典树.输入和创建完成后,開始查找. 事实上一開始就读错题目了,题目要求字符串是由其它两个输入 ...
- hdu 1247 Hat’s Words(从给的单词中找hat's word 并按字典序输出)
1.在使用mp[key]的时候它会去找键值为key的项,假设没有,他会自己主动加入一个key的项,再把value赋值为对应的初始值(value是int的话赋值为0,string的话赋值为空).所以假设 ...
- HDU 1247 - Hat’s Words - [字典树水题]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1247 Problem DescriptionA hat’s word is a word in the ...
- HDU 1247 Hat’s Words(字典树)题解
题意:给一个字符串集,要你给出n个字符串s,使s能被所给字符串集中的两个相加所得(ahat=a+hat) 思路:简单字典树题,注意查询的时候要判断所指next是否为NULL,否则会RE非法访问. 代价 ...
- HDU 1247 Hat’s Words(字典树变形)
题目链接:pid=1247" target="_blank">http://acm.hdu.edu.cn/showproblem.php? pid=1247 Pro ...
- hdu 1247:Hat’s Words(字典树,经典题)
Hat’s Words Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- HDU 1247 Hat’s Words(字典树活用)
Hat's Words Time Limit : 2000 / 1000 MS(Java / Others) Memory Limit : 65536 / 32768 K(Java / Othe ...
- HDU 1247 Hat’s Words(字典树)
http://acm.hdu.edu.cn/showproblem.php?pid=1247 题意: 给出一些单词,问哪些单词可以正好由其他的两个单词首尾相连而成. 思路: 先将所有单独插入字典树,然 ...
随机推荐
- 安装LAMP
1.首先打开命令行,获得最新的软件包 sudo apt-get install update 2.安装MySQL数据库 sudo apt-get install mysql-server mysql- ...
- Http的常见问题
A: HTTP(超文本传输协议)是一个基于请求与响应模式的.无状态的.应用层的协议. B: 文件传输协议FTP.电子邮件传输协议SMTP.域名系统服务DNS.HTTP协议等都同是应用层协议. C:HT ...
- frameset子窗口获取父窗口失败原因?
报错信息: arrow.html:44 Uncaught SecurityError: Blocked a frame with origin "null" from access ...
- OpenCV学习 物体检测 人脸识别 填充颜色
介绍 OpenCV是开源计算机视觉和机器学习库.包含成千上万优化过的算法.项目地址:http://opencv.org/about.html.官方文档:http://docs.opencv.org/m ...
- 使用PHP flush 函数的时候我们需要注意些什么呢?
WebServer(可以认为特指apache)的缓冲区.在apache module的sapi下, flush会通过调用sapi_module的flush成员函数指针,间接的调用apache的api: ...
- MySQL重置root用户密码的方法
本教程适用于采用Win2003.WinXP操作系统的迅美VPS和云主机产品. 当管理员忘记MySQL密码怎么办?屡次输入密码,仍然提示错误,网站无法正常运行,数据库也无法管理,管理员束手无策. 网站程 ...
- Zend Debugger 配置
到官网 http://www.zend.com/en/products/studio/downloads 下载 windows 版 Studio Web Debugger 打开下载得到的压缩包,里面有 ...
- ACM题目————食物链
题目描述 Description 动物王国中有三类动物 A,B,C,这三类动物的食物链构成了有趣的环形.A吃B,B吃C,C吃A. 现有N个动物,以1-N编号.每个动物都是A,B,C中的一种,但是我们并 ...
- 关于viewport的研究
昨天项目中用到了适应移动端显示的viewport,一般的使用方式如下: <meta name="viewport" content="width=device-wi ...
- phpcms常用函数
1../libs/functions/global.func.php --------------------------------------------------字符串安全处理函数--- ...