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. MYSQL 悲观锁和乐观锁简单介绍及实现

    1:悲观锁 1.1 特点: 每次查询都会进行锁行,怕"其他人"进行数据的修改. 1.2 实现步骤: 步骤1:开启事务test1,并对id=2的记录进行查询,并加锁,如:   步骤2 ...

  2. C#语言特性及发展史

    本文按照C#语言的发展历史,介绍C#每个版本的新增特性,主要参考微软官方文档.了解这些语言特性可以帮助我们更高效的编写C#代码. C# 1.0 与Visual Studio .NET 2002一起发布 ...

  3. JAVA基础(二)—— 常用的类与方法

    JAVA基础(二)-- 常用的类与方法 1 Math类 abs ceil floor 绝对值 大于等于该浮点数的最小整数 小于等于该浮点数的最大整数 max min round 两参数中较大的 两参数 ...

  4. STL容器整理

    1.vector c++STL中的可变长度数组,主要支持操作有:建立,添加到末尾,返回长度,调整大小,定义迭代器及对迭代器的具体操作.具体如下: 1.建立一个元素类型为int的可变长度数组v,最开始N ...

  5. 【pytest官方文档】解读fixtures - 1.什么是fixtures

    在深入了解fixture之前,让我们先看看什么是测试. 一.测试的构成 其实说白了,测试就是在特定的环境.特定的场景下.执行特定的行为,然后确认结果与期望的是否一致. 就拿最常见的登录来说,完成一次正 ...

  6. 《C++ Primer》笔记 第7章 类

    成员函数的声明必须在类的内部,它的定义则既可以在类的内部也可以在类的外部.作为接口组成部分的非成员函数,它们的定义和声明都在类的外部. 定义在类内部的函数是隐式的inline函数. 成员函数通过一个名 ...

  7. entitybuilder--一个简单的业务通用框架

    关于业务通用框架的思考 业务系统是千差万别的,例如,保存.更新和删除订单,或者保存订单和保存客户,走的根本不是一个流程.但是,它们还是有共同点,它们的流程大致可以分成下面的几个部分: 拿到增删改等操作 ...

  8. 微信小程序去除页面滚动条

    ::-webkit-scrollbar { width: 0; height: 0; color: transparent; display: none; } 父级元素(滚动的元素) width:10 ...

  9. 05.从0实现一个JVM语言之目标平台代码生成-CodeGenerator

    从0实现JVM语言之目标平台代码生成-CodeGenerator 源码github仓库, 如果这个系列文章对你有帮助, 希望获得你的一个star 本节相关代码生成package地址 阶段性的告别 非常 ...

  10. Python3.x 基础练习题100例(81-90)

    练习81: 题目: 809??=800??+9?? 其中??代表的两位数, 809??为四位数,8??的结果为两位数,9??的结果为3位数.求??代表的两位数,及809*??后的结果. 程序: a = ...