UVa 10391 (water problem STL) Compound Words

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.