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

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

 #include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <string>
#include <set>
#include <vector>
using namespace std; set<string> dic;
vector<string> ans;
set<string>::iterator it; int main()
{
//freopen("in.txt", "r", stdin); string s;
while(cin >> s) dic.insert(s);
for(it = dic.begin(); it != dic.end(); it++)
{
s = *it; int l = s.length();
for(int i = ; i < l; i++)
{
string s1 = s.substr(, i);
string s2 = s.substr(i, l - i);
if(dic.count(s1) && dic.count(s2))
{
ans.push_back(s);
break;
}
}
} sort(ans.begin(), ans.end());
for(int i = ; i < ans.size(); i++) cout << ans[i] << endl; return ;
}

代码君

UVa 10391 (水题 STL) Compound Words的更多相关文章

  1. UVa 1593 (水题 STL) Alignment of Code

    话说STL的I/O流用的还真不多,就着这道题熟练一下. 用了两个新函数: cout << std::setw(width[j]);    这个是设置输出宽度的,但是默认是在右侧补充空格 所 ...

  2. UVa 1595 (水题) Symmetry

    颓废的一个下午,一直在切水题,(ˉ▽ ̄-) 首先如果这些点是对称的话,那么它们的对称轴就是x = m,m是横坐标的平均值. 把这些点放到一个集合里,然后扫描每个点,计算出它关于x = m的对称点,看这 ...

  3. UVa 10935 (水题) Throwing cards away I

    直接用STL里的queue模拟即可. #include <cstdio> #include <queue> using namespace std; ; int discard ...

  4. UVa 400 (水题) Unix ls

    题意: 有n个文件名,排序后按列优先左对齐输出.设最长的文件名的长度为M,则最后一列长度为M,其他列长度为M+2. 分析: 这道题很简单,但要把代码写的精炼,还是要好好考虑一下的.lrj的代码中有两个 ...

  5. UVa 11040 (水题) Add bricks in the wall

    题意: 45块石头如图排列,每块石头上的数等于下面支撑它的两数之和,求其余未表示的数. 分析: 首先来计算最下面一行的数,A71 = A81 + A82 = A91 + 2A92 + A93,变形得到 ...

  6. UPC OJ 一道水题 STL

    Problem C: 字符串游戏 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 10  Solved: 3 [Submit][Status][Web ...

  7. Square Numbers UVA - 11461(水题)

    #include <iostream> #include <cstdio> #include <sstream> #include <cstring> ...

  8. UVa 489 HangmanJudge --- 水题

    UVa 489 题目大意:计算机给定一个单词让你猜,你猜一个字母,若单词中存在你猜测的字母,则会显示出来,否则算出错, 你最多只能出错7次(第6次错还能继续猜,第7次错就算你失败),另注意猜一个已经猜 ...

  9. UVa 1339 Ancient Cipher --- 水题

    UVa 1339 题目大意:给定两个长度相同且不超过100个字符的字符串,判断能否把其中一个字符串重排后,然后对26个字母一一做一个映射,使得两个字符串相同 解题思路:字母可以重排,那么次序便不重要, ...

随机推荐

  1. Unity bundle的制作和使用

    原地址:http://unity3d.9ria.com/?p=2863 Unity有个很好的功能,大致是很多专注于PC的engine没有提供的(因为没有必要),就是能加载主包外的资源,这个主包外的资源 ...

  2. AESEncrypter加密算法代码示例

    package testJava.java; import java.security.SecureRandom; import java.util.Base64; import javax.cryp ...

  3. leetcode single number系列

    这个系列一共有三题,第一题是一组数里除了一个数出现一次之外,其他数都是成对出现,求这个数. 第二题是一组数里除了两个数出现一次外,其他数都是成对出现,求这两个数 第三题是一组数里除了一个数出现一次外, ...

  4. HDU 1041 Computer Transformation (简单大数)

    Computer Transformation http://acm.hdu.edu.cn/showproblem.php?pid=1041 Problem Description A sequenc ...

  5. HDU 1978 How many ways(动态规划)

    How many ways http://acm.hdu.edu.cn/showproblem.php?pid=1978 Problem Description 这是一个简单的生存游戏,你控制一个机器 ...

  6. OneApm,NewRelic

    https://newrelic.com/ http://www.csdn.net/article/2013-03-25/2814631-new-relic-mobile-app-real-time- ...

  7. hibernate初次配置问题

    1.自动创建表结构 在hibernate.cfg.xml配置文件中修改 <property name="hibernate.hbm2ddl.auto">update&l ...

  8. 李洪强iOS开发之- 实现简单的弹窗

     李洪强iOS开发之- 实现简单的弹窗 实现的效果:  112222222222223333333333333333

  9. uploadify IO Error/http error 413

    阿里云的服务器 linux 服务器,php 环境,上传附件问题,记录分享一下: 开始测试的时候,都是图片,小附件,没什么问题 系统上线后,发现大的附件上传 有问题,报错 IO Error 开始检查程序 ...

  10. IIS7 ASP.NET 未被授权访问所请求的资源

    IIS7 ASP.NET 未被授权访问所请求的资源 ASP.NET 未被授权访问所请求的资源.请考虑授予 ASP.NET 请求标识访问此资源的权限. ASP.NET 有一个在应用程序没有模拟时使用的基 ...