码迷,mamicode.com
首页 > 其他好文 > 详细

HDU 1247-Hat’s Words(set)

时间:2014-08-22 16:22:08      阅读:233      评论:0      收藏:0      [点我收藏+]

标签:des   style   color   java   os   io   strong   for   ar   

Hat’s Words

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 8120    Accepted Submission(s): 2942


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
字典树专题的题,用set水过去的。。题意:给一堆字符串,把其中可以由其他两个字符串连接起来的字符串输出。
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
using namespace std;
const int INF=1<<27;
const int maxn=5100;
int main()
{
	ios::sync_with_stdio(false);
	string x,a,b;
	set <string> s;
	while(cin>>x)
		s.insert(x);
	set <string>::iterator it=s.begin();
	while(it!=s.end()){
	x=*it;int n=x.size();
	for(int i=0;i<n;i++)
	{
		a.assign(x,0,i+1);
		b.assign(x,i+1,n-i-1);
		if(s.count(a)&&s.count(b))
		{cout<<x<<endl;break;}
	}
	++it;
	}
	return 0;
}


HDU 1247-Hat’s Words(set)

标签:des   style   color   java   os   io   strong   for   ar   

原文地址:http://blog.csdn.net/qq_16255321/article/details/38757691

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!