uva 10391 Compound Words <set>
Compound Words
You are to find all the two-word compound words in a dictionary. A two-word compound word is a word in the dictionary that is theconcatenation of exactly two other words in the dictionary.
Input
Standard input consists of a number of lowercase words, one per line,in alphabetical order. There will be no more than 120,000 words.
Output
Your output should contain all the compound words, one per line, inalphabetical order.
Sample Input
a
alien
born
less
lien
never
nevertheless
new
newborn
the
zebra
Sample Output
alien
newborn 用set做
#include <iostream>
#include <set>
#include <string>
using namespace std; set<string>dic;
set<string>::iterator t; int main()
{
string word;
while(cin >> word)dic.insert(word); for(t = dic.begin(); t != dic.end(); t++){
word = *t;
int n = word.length(); for(int i = ; i < n - ; i++ ){
string s1=word.substr(,i+),s2 = word.substr(i+,n-i-);
if( (dic.count(s1)) && (dic.count(s2)) ){
cout << word <<endl;
break;
}
}
}
//system("pause");
return ;
}
dic.count(s2) 在set dic中计算s2的个数,并返回其个数。
uva 10391 Compound Words <set>的更多相关文章
- UVA 10391 Compound Words
Problem E: Compound Words You are to find all the two-word compound words in a dictionary. A two-wor ...
- UVA 10391 - Compound Words 字符串hash
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...
- 复合词(Compound Words, UVa 10391)(stl set)
You are to find all the two-word compound words in a dictionary. A two-word compound word is a word i ...
- Compound Words UVA - 10391
You are to find all the two-word compound words in a dictionary. A two-word compound word is a wor ...
- UVa 10391 (水题 STL) Compound Words
今天下午略感无聊啊,切点水题打发打发时间,=_=|| 把所有字符串插入到一个set中去,然后对于每个字符串S,枚举所有可能的拆分组合S = A + B,看看A和B是否都在set中,是的话说明S就是一个 ...
- 【UVA】10391 Compound Words(STL map)
题目 题目 分析 自认已经很简洁了,虽说牺牲了一些效率 代码 #include <bits/stdc++.h> using namespace std; set <s ...
- UVA 10391 stl
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
- uva 10391
这个题,单纯做出来有很多种方法,但是时间限制3000ms,因此被TL了不知道多少次,关键还是找对最优解决方法,代码附上: #include<bits/stdc++.h> using nam ...
- 复合词 (Compund Word,UVa 10391)
题目描述: 题目思路: 用map保存所有单词赋键值1,拆分单词,用map检查是否都为1,即为复合词 #include <iostream> #include <string> ...
随机推荐
- C++中的虚函数
代码: #include <iostream> #include <cstring> using namespace std; class Base{ public: virt ...
- winPcap_6_不用回调方法捕获数据包
用 pcap_next_ex() 函数代替 _5_ 中的 pcap_loop()函数: pcap_loop()函数是基于回调的原理来进行数据捕获,这是一种精妙的方法,并且在某些场合中,它是一种很好的选 ...
- C语言--位运算符
一.位运算符 1.按位与:& 1> 功能 * 只有对应的两个二进制位为1时,结果位才为1,否则为0 * 举例:10用二进制表示为1010, 7用二进制表示为0111.对两个数值进行&a ...
- 转载--http协议学习和总结
http的了解一直停留在一知半解的程度,今天看到阿蜜果大大的博客,果断学习了,这里做个转载,希望阿蜜果大大不要怪罪~~ 3.1 Cookie和Session Cookie和Session都为了用来保存 ...
- Tomcat 6.0.32 +Spring dbcp datasource关闭Tomcat出现严重异常
异常如下: 信息: Pausing Coyote HTTP/ -- :: org.apache.catalina.core.StandardService stop 信息: Stopping serv ...
- shell 脚本监控程序是否正在执行, 如果没有执行, 则自动启动该进程
代码里面监控1个进程, 代码很简单, 我就不讲解了, 有不懂的, 可以在回复里面问. 我看见了会给予讲解. 当然了, 该脚本要执行,你需要开启系统的定时器进程 crond , 并且编辑配置文件. 执行 ...
- MessagerService总结
一.整体工程图 二.messenger_service_binding.xml <?xml version="1.0" encoding="utf-8"? ...
- Android 图片合成:添加蒙板效果 不规则相框 透明度渐变效果的实现
Android 图片合成:添加蒙板效果 不规则相框 透明度渐变效果的实现 暂时还未有时间开发这效果,所以先贴出来. 先贴一张效果图,这是一张手机截屏: 左上方的风景图:背景图片 右上方的人物图:前景图 ...
- Eclipse代码提示功能设置(Java & Eclipse+CDT C/C++)
http://developer.51cto.com/art/200907/136242.htm http://blog.chinaunix.net/u/21684/showart_462486.ht ...
- bst 二叉搜索树简单实现
//数组实现二叉树: // 1.下标为零的元素为根节点,没有父节点 // 2.节点i的左儿子是2*i+1:右儿子2*i+2:父节点(i-1)/2: // 3.下标i为奇数则该节点有有兄弟,否则又左兄弟 ...