UVa 10391 - Compound Words
2015-01-22 23:40
363 查看
Problem E: Compound Words
You are to find all the two-word compound words in a dictionary. A two-word compound word is a word in the dictionary that is the concatenation of exactly two other words in the dictionary.Input
Standard input consists of a number of lowercase words, one per line, in alphabetical order. There will be no more than 120,000 words.Output
Your output should contain 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
判断复合词,即该词能不能由已给出的词组成
例如,alien可由a与lien组成
用set ,记录每个词语,再枚举该词可以的组成形式
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<algorithm> using namespace std; #include<set> #include<map> int main() { string a,b,c; set<string>s; set<string>::iterator p; while(cin>>a) { s.insert(a); } int n,i,j,k; p=s.begin(); while(p!=s.end()){ c=*p;///cout<<c<<endl; n=c.length(); for(i=0;i<n-1;i++){ a.clear(); b.clear(); for(j=0;j<=i;j++)/// 得到第一个词a a+=c[j]; k=j; for(j=0;k<n;j++,k++)/// 第二个词b b+=c[k]; ///cout<<a<<" "<<b<<"+++"<<endl; if(s.count(a)&&s.count(b)) /// 枚举可以组成复合词的两个单词,判断它们是不是在集合中出现过 { cout<<c<<endl; break; } } p++; } }
相关文章推荐
- UVa-10391 Compound Words
- 5-5 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
- UVa 10391 - Compound Words
- UVA 10391 Compound Words
- uva 10391 Compound Words (字符串-hash)
- uva10391 Compound Words
- UVA - 10391 Compound Words
- Compound Words(复合词) UVA 10391
- uva 10391 compound words
- UVa 10391 - Compound Words
- uva 10391 Compound Words
- uva 10391 Compound Words (字符串-hash)
- UVA 10391 - Compound Words