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&#39;s word 并按字典序输出)的更多相关文章

  1. HDU 1247 Hat’s Words (字符串匹配,暴力)

    题意: 给出一堆单词,如果有一个单词可以分成左右串两个单词,并且在所给的一堆单词中存在,就是hat词,统计所有这样的词,并按字典序输出. 思路: 注意定义,一个hat词可以被两部分已经存在的词组成,那 ...

  2. hdu 1247:Hat’s Words(字典树,经典题)

    Hat’s Words Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  3. HDU 1247 Hat’s Words(字典树活用)

    Hat's Words Time Limit : 2000 / 1000 MS(Java / Others)    Memory Limit : 65536 / 32768 K(Java / Othe ...

  4. HDU 1247 - Hat’s Words - [字典树水题]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1247 Problem DescriptionA hat’s word is a word in the ...

  5. HDU 1247 Hat’s Words(字典树变形)

    题目链接:pid=1247" target="_blank">http://acm.hdu.edu.cn/showproblem.php? pid=1247 Pro ...

  6. HDU 1247 Hat’s Words(字典树)

    http://acm.hdu.edu.cn/showproblem.php?pid=1247 题意: 给出一些单词,问哪些单词可以正好由其他的两个单词首尾相连而成. 思路: 先将所有单独插入字典树,然 ...

  7. 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 ...

  8. HDU 1247 Hat’s Words

    Hat’s Words Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  9. hdu 1247 Hat’s Words(字典树)

    Hat's Words Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

随机推荐

  1. Redis基础---消息通信模式

    Redis发送订阅通信模式 Redis发布订阅(pub/sub)是一种消息通信模式:发送者(pub)发送消息,订阅者(sub)接收消息. Redis 发布订阅(pub/sub)实现了消息系统,发送者( ...

  2. 372 Super Pow 超级次方

    你的任务是计算 ab 对 1337 取模,a 是一个正整数,b 是一个非常大的正整数且会以数组形式给出.示例 1:a = 2b = [3]结果: 8示例 2:a = 2b = [1,0]结果: 102 ...

  3. 237 Delete Node in a Linked List 删除链表的结点

    编写一个函数,在给定单链表一个结点(非尾结点)的情况下,删除该结点. 假设该链表为1 -> 2 -> 3 -> 4 并且给定你链表中第三个值为3的节点,在调用你的函数后,该链表应变为 ...

  4. 我要上google

    我要上google 一.下载google浏览器(百度下载) 二.获取和运行xx-net 1.https://github.com/XX-net/XX-Net 2.解压下载的xx-net,运行文件夹中的 ...

  5. Pyhton TestCase运行闪退与失败,原因不详。。。

    把源码贴上来,希望某位大神可以指点迷津: """Unit test for odbchelper.py This program is part of "Div ...

  6. Eclipse+JUnit+Selenium配置

    运行环境:Windows XP.Firefox.Firefox需要安装在标准路径下"C:\Program Files\Mozilla Firefox\firefox.exe",否则 ...

  7. Linux 学习(二)

    Linux相关命令 命令 说明 startx 当前用户界面切换至图形界面 init5 切换至另一用户的图形化界面 init3 从图形界面切换回文本界面 pwd 显示当前用户路径 logout 注销 s ...

  8. HiveServer2后台运行

    nohup hive --service hiveserver2 & 或者直接: nohup hiveserver2 &

  9. HDU_1556_线段树区间更新

    Color the ball Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)To ...

  10. codeforces_455B

    B. A Lot of Games time limit per test 1 second memory limit per test 256 megabytes input standard in ...