hdu1247 Hat’s Words
2016-02-04 16:58
344 查看
Hat’s Words
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 11867 Accepted Submission(s): 4225
Problem Description
A hat’s word is a word in the dictionary that is the concatenation of exactly two other words in the dictionary.
You are to find all the hat’s words in a dictionary.
Input
Standard input consists of a number of lowercase words, one per line, in alphabetical order. There will be no more than 50,000 words.
Only one case.
Output
Your output should contain all the hat’s words, one per line, in alphabetical order.
Sample Input
a
ahat
hat
hatword
hziee
word
Sample Output
ahat
hatword
Author
戴帽子的
Recommend
Ignatius.L | We have carefully selected several similar problems for you: 1298 1800 2846 2222 1711
代码:
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<set>
using namespace std;
const int maxn=5e4;
string s[maxn+5];
set<string> q;
int main()
{
//freopen("1.in","r",stdin);
string s1,s2;
int n,i,j,k;
for(n=0;cin>>s
;n++)q.insert(s
);
for(i=0;i<n;i++)
for(s1="",k=s[i].length(),j=0;j<k;j++)
{
s1+=s[i][j],s2=s[i].substr(j+1);
if(q.find(s1)!=q.end() && q.find(s2)!=q.end())
{
cout<<s[i]<<endl;
break;
}
}
return 0;
}
相关文章推荐
- js中function的带括号和不带括号的区别
- mybatis+jstl表达式
- htaPyfilpmiS.71
- 安卓日记——volley常用方法介绍
- 算法-踢人游戏
- C#基础
- 抽象方法真的不能实例化么?
- Thrift
- google group翻译(1)
- Scatter文件编写
- android 找不到启动activity
- 来自Uber的12条架构重构经验
- Java基础:包装类
- C++/MFC修行之路(2) 自定义消息
- 基于特定值来推断隐藏显示元素的jQuery插件
- 关于SVG和cavas来做更加炫的效果以及年前总结
- 21天学习android开发教程之MediaPlayer
- UVA1626 - Brackets sequence
- 如何用消息系统避免分布式事务?
- RtlAnsiStringToUnicodeSize routine