Compound wordstime limit:5000msmemory limit:32768kbthis problem would be judged onZju. Original id:1825
64-bit integer IO format: %lld Java class name: Main You is to find all the two-word compound words in a dictionary. A two-word compound word is a word in the dictionary that's the concatenation of exactly the other words in the Dictionar Y.
Input
Standard input consists of a number of lowercase words, one per line, in alphabetical order. There'll be is 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
SourceUniversity of Waterloo Local Contest 1996.09.28 problem Solving: Long time no code to start a brain residue
1#include <bits/stdc++.h>2 using namespacestd;3unordered_set<string>us;4 stringword[1000010];5 intMain () {6Ios::sync_with_stdio (false);7 inttot =0;8 while(Cin>>word[tot]) Us.insert (word[tot++]);9 for(inti =0; i < tot; ++i) {Ten if(Word[i].length () >1) { One for(intj =1, Len = Word[i].length (); J < Len; ++j) { A stringA = Word[i].substr (0, j); - stringb =Word[i].substr (j); - if(Us.count (a) &&Us.count (b)) { thecout<<word[i]<<Endl; - Break; - } - } + } - } + return 0; A}
View Code
ZOJ 1825 Compound Words