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>的更多相关文章

  1. UVA 10391 Compound Words

    Problem E: Compound Words You are to find all the two-word compound words in a dictionary. A two-wor ...

  2. UVA 10391 - Compound Words 字符串hash

    http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&p ...

  3. 复合词(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 ...

  4. 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 ...

  5. UVa 10391 (水题 STL) Compound Words

    今天下午略感无聊啊,切点水题打发打发时间,=_=|| 把所有字符串插入到一个set中去,然后对于每个字符串S,枚举所有可能的拆分组合S = A + B,看看A和B是否都在set中,是的话说明S就是一个 ...

  6. 【UVA】10391 Compound Words(STL map)

    题目 题目     分析 自认已经很简洁了,虽说牺牲了一些效率     代码 #include <bits/stdc++.h> using namespace std; set <s ...

  7. UVA 10391 stl

    https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  8. uva 10391

    这个题,单纯做出来有很多种方法,但是时间限制3000ms,因此被TL了不知道多少次,关键还是找对最优解决方法,代码附上: #include<bits/stdc++.h> using nam ...

  9. 复合词 (Compund Word,UVa 10391)

    题目描述: 题目思路: 用map保存所有单词赋键值1,拆分单词,用map检查是否都为1,即为复合词 #include <iostream> #include <string> ...

随机推荐

  1. OpenCV——手势识别

    使用ANN神经网络训练数据后进行手势识别. #include "header.h" int main() { ; //训练每类图片数量 ; //训练类数3:石头剪刀布 ; ; st ...

  2. C# winform 窗体 彻底退出窗体的方法

      1.this.Close();   只是关闭当前窗口,若不是主窗体的话,是无法退出程序的,另外若有托管线程(非主线程),也无法干净地退出: 2.Application.Exit();  强制所有消 ...

  3. EF 执行顺序--先删除在更新和添加

    public void AcceptAllChanges() { if (this.ObjectStateManager.SomeEntryWithConceptualNullExists()) { ...

  4. JS函数自动执行

    关于让网页中的JavaScript函数自动执行,方法就多洛,但是万变不离其宗,下面给大家介绍一下! 前提条件,网页中必须有JS函数代码,或者,使用文件导入的方法也行: 在HTML中的Head区域中,有 ...

  5. 【笔记】Linux 和 Unix 作业控制

    Linux 和 Unix 属于多任务的操作系统,也就是说一个系统在同一时间段内能运行多重任务(进程). 作业控制不只是能够停止/挂起(stop/suspend)正在执行的进程(命令),也可以继续/唤醒 ...

  6. npm install 本地安装与全局安装

    npm的包安装分为本地安装(local).全局安装(global)两种,从敲的命令行来看,差别只是有没有-g而已: npm install grunt # 本地安装 npm install -g gr ...

  7. 开心菜鸟系列学习笔记------------javascript(6)

    一.作用域链            1)函数的生命周期:            函数的生命周期分为创建和激活阶段(调用时),让我们详细研究它.            作用域链与一个执行上下文相关,变量 ...

  8. ORA-16014报错解决

    今天在本地数据库操作的时候报错: SQL> alter database open;alter database open*第 1 行出现错误:ORA-16014: 日志 3 的序列号 55 未 ...

  9. hdu 1829 A Bug's Life(并查集)

                                                                                                    A Bu ...

  10. UVA 10594-Date Flow(无向图的最小费用网络流+题目给的数据有误)

    题意:给一个有N个点的无向图,要求从1向N传送一定的数据,每条边的容量是一定的,如果能做到,输出最小的费用,否则输出Impossible. 解析:由于是无向图,所以每个有连接的两个点要建4条边,分别是 ...