hdu 1247 Hat’s Words(从给的单词中找hat's word 并按字典序输出)
1.在使用mp[key]的时候它会去找键值为key的项,假设没有,他会自己主动加入一个key的项,再把value赋值为对应的初始值(value是int的话赋值为0,string的话赋值为空)。所以假设是插入的话能够用insert。假设是查找的话能够使用find。这样能够节省开销。
查找的时间复杂度为O(logn)
watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center" alt="">
2.
代码:
#include<iostream>
#include<string>
#include<map>
using namespace std; string word[50005];
map<string,int> mp;//用平衡二叉树实现的,按key从小到大排 int main()
{
int i=0;
//printf("%d\n",k.max_size());用来看容器的容量
while(cin>>word[i++])//用ctrl+z然后enter结束循环
{
mp[word[i-1]]=1;//mp[]中的[]已重载,注意是i-1啊啊! !。!。!
}
map<string,int>::iterator it;
for(it=mp.begin(); it!=mp.end(); it++)
{
string w=it->first;
for(i=1; i<w.length()-1; i++)
{
string w1(w,0,i);//复制[0,i)
string w2(w,i);//从w的i位置開始复制
if(mp.find(w1)!=mp.end()&&mp.find(w2)!=mp.end())
{
cout<<w<<endl;
break;
}
}
}
return 0;
}
hdu 1247 Hat’s Words(从给的单词中找hat's word 并按字典序输出)的更多相关文章
- HDU 1247 Hat’s Words (字符串匹配,暴力)
题意: 给出一堆单词,如果有一个单词可以分成左右串两个单词,并且在所给的一堆单词中存在,就是hat词,统计所有这样的词,并按字典序输出. 思路: 注意定义,一个hat词可以被两部分已经存在的词组成,那 ...
- 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 Problem DescriptionA hat’s word is a word in the ...
- HDU 1247 Hat’s Words(字典树变形)
题目链接:pid=1247" target="_blank">http://acm.hdu.edu.cn/showproblem.php? pid=1247 Pro ...
- HDU 1247 Hat’s Words(字典树)
http://acm.hdu.edu.cn/showproblem.php?pid=1247 题意: 给出一些单词,问哪些单词可以正好由其他的两个单词首尾相连而成. 思路: 先将所有单独插入字典树,然 ...
- HDU 1247 Hat's Words (map+string)
Hat’s Words Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- 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/Others) Tota ...
随机推荐
- c/c++导出lua绑定
[转载]https://note.youdao.com/share/?id=0f4132271151c4b62f9afb712e8304d9&type=note#/ 1.在纯C环境下,把C函数 ...
- arp学习笔记(linux高性能服务编程)
先看看arp的定义吧 现在linux运行这条命令 tcpdump -i eth0:1 -ent '(dst 192.168.5.190 and src 192.168.5.109)or( dst 19 ...
- LN : leetcode 242 Valid Anagram
lc 242 Valid Anagram 242 Valid Anagram Given two strings s and t, write a function to determine if t ...
- python中os模块中文帮助
python中os模块中文帮助 python中os模块中文帮助文档文章分类:Python编程 python中os模块中文帮助文档 翻译者:butalnd 翻译于2010.1.7——2010.1.8 ...
- django-registration (1048, “Column 'last_login' cannot be null”)
Go to your database (MySQL Terminal): $ mysql mysql> SELECT * FROM django_migrations; If you see ...
- bower——基本使用
基本概念 bower可以解决项目的静态文件依赖的问题 bower是用nodejs开发的,所以要现状nodejs 安装nodejs应用程序,网上自行下载 检验是否成功安装,打开电脑cmd,执行node ...
- firefox + pentadactyl 实现纯绿色高效易扩展浏览器(同时实现修改默认状态栏样式)
这几天开始使用firefox+pentadactyl来搭建一个开源.可扩展.完全绿化的浏览器环境,以便随身带着使用,其中firefox的使用了24.0的长期支持版, 这边版本稳定, 快速, 兼容性好, ...
- java生成excel
package test.poi; import java.io.File; import java.io.FileOutputStream; import java.io.OutputStream; ...
- union与union all
union在合并A和B表的时候会先将B表中的数据与A表进行比较,若A表中已存在,则忽略. union all合并时则不比较,直接将A表与B表进行合并. 因此,若已知A与B不存在重复数据,那么union ...
- Stack frame
http://en.citizendium.org/wiki/Stack_frame In computer science, a stack frame is a memory management ...