A little bored this afternoon, cut off the water to pass the time, =_=| |
Insert all the strings into a set, and then for each string s, enumerate all possible split combinations s = a + B, and see if A and B are all in set, which means that s is a compound word.
1#include <iostream>2#include <algorithm>3#include <cstdio>4#include <cstring>5#include <string>6#include <Set>7#include <vector>8 using namespacestd;9 Ten Set<string>dic; Onevector<string>ans; A Set<string>:: iterator it; - - intMain () the { - //freopen ("In.txt", "R", stdin); - - strings; + while(Cin >>s) dic.insert (s); - for(it = Dic.begin (); It! = Dic.end (); it++) + { As = *it;intL =s.length (); at for(inti =1; I < L; i++) - { - stringS1 = S.substr (0, i); - stringS2 = s.substr (i, L-i); - if(Dic.count (S1) &&dic.count (S2)) - { in Ans.push_back (s); - Break; to } + } - } the * sort (Ans.begin (), Ans.end ()); $ for(inti =0; I < ans.size (); i++) cout << Ans[i] <<Endl;Panax Notoginseng - return 0; the}code June
UVa 10391 (water problem STL) Compound Words