HDU 1247-Hat’s Words(set)
来源:互联网 发布:红色 知乎 编辑:程序博客网 时间:2024/05/19 02:04
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.
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.
Only one case.
Output
Your output should contain all the hat’s words, one per line, in alphabetical order.
Sample Input
aahathathatwordhzieeword
Sample Output
ahathatword字典树专题的题,用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;}
3 0
- HDU 1247-Hat’s Words(set)
- hdu--1247--Hat’s Words(一般)
- HDU 1247 Hat's words(Trie)
- hdu 1247 Hat’s Words(Trie)
- HDU 1247 Hat’s Words (Trie)
- hdu 1247 Hat’s Words
- hdu 1247 Hat's words
- hdu 1247 Hat’s Words
- HDU 1247 - Hat’s Words
- hdu 1247 Hat’s Words
- hdu 1247 Hat’s Words
- hdu 1247 Hat’s Words
- hdu 1247 Hat’s Words
- hdu 1247 Hat’s Words
- HDU 1247 Hat’s Words
- hdu 1247 Hat's Words
- hdu-1247 Hat’s Words
- HDU 1247 Hat’s Words
- Reduced ID Numbers(POJ 2769)
- Lua学习笔记 第六章 深入函数
- apk签名问题
- c 语言break 和 continue的区别
- 需求调研的内容和工作指引
- HDU 1247-Hat’s Words(set)
- Fiddler 教程
- hdu 1532 Drainage Ditches(网络流dinic模板)
- Nivoslider:丰富的图片切换效果
- Tomcat启动时,spring加载配置文件applicationContext.xml出错,抛出nested exception is og.xml.sax.SAXParseException
- poj 2498 StuPId
- leetcode之Container With Most Water 和Trapping Rain Water
- POJ 2195 Going Home
- logback 常用配置详解(方便以后查阅)