首页 > 其他 > 详细

UVa 10391 (水题 STL) Compound Words

时间:2015-04-24 18:11:52      阅读:281      评论:0      收藏:0      [点我收藏+]

今天下午略感无聊啊,切点水题打发打发时间,=_=||

把所有字符串插入到一个set中去,然后对于每个字符串S,枚举所有可能的拆分组合S = A + B,看看A和B是否都在set中,是的话说明S就是一个复合词。

技术分享
 1 #include <iostream>
 2 #include <algorithm>
 3 #include <cstdio>
 4 #include <cstring>
 5 #include <string>
 6 #include <set>
 7 #include <vector>
 8 using namespace std;
 9 
10 set<string> dic;
11 vector<string> ans;
12 set<string>::iterator it;
13 
14 int main()
15 {
16     //freopen("in.txt", "r", stdin);
17 
18     string s;
19     while(cin >> s) dic.insert(s);
20     for(it = dic.begin(); it != dic.end(); it++)
21     {
22         s = *it; int l = s.length();
23         for(int i = 1; i < l; i++)
24         {
25             string s1 = s.substr(0, i);
26             string s2 = s.substr(i, l - i);
27             if(dic.count(s1) && dic.count(s2))
28             {
29                 ans.push_back(s);
30                 break;
31             }
32         }
33     }
34 
35     sort(ans.begin(), ans.end());
36     for(int i = 0; i < ans.size(); i++) cout << ans[i] << endl;
37 
38     return 0;
39 }
代码君

 

UVa 10391 (水题 STL) Compound Words

原文:http://www.cnblogs.com/AOQNRMGYXLMV/p/4453688.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!