10391 - Compound Words
来源:互联网 发布:强制竖屏软件 编辑:程序博客网 时间:2024/05/16 15:31
You are to findall the two-word compound words in a dictionary. A two-word compound word is aword in the dictionary that is the concatenation of exactly two other words inthe dictionary.
Input
Standard inputconsists of a number of lowercase words, one per line, in alphabetical order.There will be no more than 120,000 words.
Output
Your output shouldcontain all the compound words, one per line, in alphabetical order.
Sample Input
a
alien
born
less
lien
never
nevertheless
new
newborn
the
zebra
Sample Output
alien
newborn
代码:
#include<iostream>
#include<string>
#include<set>
using namespacestd;
set<string>dict;
int main()
{
string s;
while(cin>>s)
{
dict.insert(s);
}
s="";
for(set<string>::iteratorit=dict.begin(); it!=dict.end(); it++)
{
s=*it;
for(int i=1; i<s.length(); i++)
{
if(dict.find(s.substr(0,i))!=dict.end()&&dict.find(s.substr(i,s.length()-i))!=dict.end())
{
cout<<s<<endl;
break;
}
}
}
return 0;
}
- uva 10391 compound words
- UVa 10391 - Compound Words
- uva 10391 - Compound Words
- uva 10391 - Compound Words
- UVa 10391 - Compound Words
- UVa 10391 - Compound Words
- Compound Words 10391
- uva 10391 - Compound Words
- 10391 - Compound Words
- UVA 10391 Compound Words
- UVA 10391 - Compound Words
- Uva-10391-Compound Words
- UVa 10391 - Compound Words
- uva--10391 - Compound Words
- UVA 10391 Compound Words
- UVa:10391 Compound Words
- uva 10391 Compound Words
- 10391Compound Words
- 1594 - Ducci Sequence
- 1595 - Symmetry
- 1596 - Bug Hunt
- 1597 - Searching the Web
- 1598 - Exchange
- 10391 - Compound Words
- 10763 - Foreign Exchange
- [CODEVS 3044] 矩形面积求并
- 10935 - Throwing cards away I
- 12100—Printer Queue
- 12333 - Revenge of Fibonacci
- Eclipse + JLink 编译和调试TQ2440裸机程序【我使用的是win64版本的eclipse】
- 12504 - Updating a Dictionary
- Matrix Chain Multiplication-geeksforgeeks