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 the concatenation 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, in alphabetical order.

Sample Input

a
alien
born
less
lien
never
nevertheless
new
newborn
the
zebra

Sample Output

alien
newborn

HINT

  没想到更加高效的办法,就是使用set存储字典,用vector存储每一个单词。读入完毕对vector每一个元素中的单词进行分割处理,然后查找set是否有这两个分割的单词,有就输出。输出之后就跳出循环,否则会输出多个相同的单词。

Accepted

#include<iostream>
#include<algorithm>
#include<set>
#include<string>
#include<vector>
using namespace std; int main()
{
string s, s1, s2;
set<string>str;
vector<string>arr;
while (cin >> s) {
arr.push_back(s);
str.insert(s);
}
for (int i = 0;i < arr.size();i++)
{
for (int j = 1;j < arr[i].length();j++)
{
s1 = arr[i].substr(arr[i].length() - j);
s2 = arr[i].substr(0,arr[i].length() - j);
if (str.count(s1) && str.count(s2)) {
cout << arr[i] << endl;
break;
}
}
}
}

Compound Words UVA - 10391的更多相关文章

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

  2. uva 10391 Compound Words <set>

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

  3. UVA 10391 Compound Words

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

  4. UVA 10391 - Compound Words 字符串hash

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

  5. UVa 10391 (水题 STL) Compound Words

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

  6. UVA 10391 stl

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

  7. uva 10391

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

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

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

  9. UVa第五章STL应用 习题((解题报告))具体!

    例题5--9 数据库 Database UVa 1592 #include<iostream> #include<stdio.h> #include<string.h&g ...

随机推荐

  1. Go的map

    目录 map 一.map的创建 1.map的类型 2.定义并初始化 二.给map添加元素 三.获取map的元素 四.删除map的元素 五.获取map的长度 六.map的类型 七.map的相等性 八.循 ...

  2. Kubernetes-6.Service

    docker version:20.10.2 kubernetes version:1.20.1 本文概述Kubernetes Service的基本原理和使用. 服务 Service是将运行在一组Po ...

  3. JPEG解码——(5)反量化和逆ZigZag变换

    本篇是该系列的第五篇,承接上篇huffman解码,介绍接下来的两个步骤--反量化和逆zigzag变换,即IDCT前的两个步骤. 需要说明的是,这两个步骤可以颠倒,本人的实现是,先反量化,再逆ZigZa ...

  4. 《C++ Primer》笔记 第6章 函数

    任意两个形参都不能同名,而且函数最外层作用域中的局部变量也不能使用与函数形参一样的名字(形参就相当于该函数的局部变量). 形参名是可选的,但是由于我们无法使用未命名的形参,所以形参一般都应该有个名字. ...

  5. XAPKInstaller - XAPK游戏包安装器

    XAPKInstaller 一个用于安装XAPK游戏包的安装器. 程序需要读写存储与获取已安装应用权限才可正常运行. 长按条目可显示文件的详细信息. SDK小于24(Android N)的设备会显示应 ...

  6. C++对象的生存期笔记

    下面随笔记录了C++对象的生存期知识 静态生存期 这种生存期与程序的运行期相同. 在文件作用域中声明的对象具有这种生存期. 在函数内部声明静态生存期对象,要冠以关键字static . 动态生存期 块作 ...

  7. ant-design-vue中table自定义列

    1. 使用背景 在项目中使用ant-vue的a-table控件过程中,需要显示序号列或者在列中显示图片,超链,按钮等UI信息.经过查询文档customCell和customRender可以实现以上需求 ...

  8. SpringMVC-02 第一个SpringMVC程序

    SpringMVC-02 第一个SpringMVC程序 第一个SpringMVC程序 配置版 新建一个Moudle , springmvc-02-hello,确定依赖导入进去了 1.配置web.xml ...

  9. golang——gRPC学习

    1.获取gRPC 环境变量GOPATH的src目录下执行: git clone https://github.com/grpc/grpc-go.git google.golang.org/grpc g ...

  10. reverseLinkedList(翻转链表)

    ReverseLinkedList(翻转链表) 链表是一种物理存储单元上非连续.非顺序的存储结构,数据元素的逻辑顺序是通过链表中的指针链接次序实现的.非连续.非顺序指的是,通过指针把一组零散的内存块串 ...