Compound Words UVA - 10391
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的更多相关文章
- 复合词(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 ...
- uva 10391 Compound Words <set>
Compound Words You are to find all the two-word compound words in a dictionary. A two-word compound ...
- 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 ...
- UVa 10391 (水题 STL) Compound Words
今天下午略感无聊啊,切点水题打发打发时间,=_=|| 把所有字符串插入到一个set中去,然后对于每个字符串S,枚举所有可能的拆分组合S = A + B,看看A和B是否都在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> ...
- UVa第五章STL应用 习题((解题报告))具体!
例题5--9 数据库 Database UVa 1592 #include<iostream> #include<stdio.h> #include<string.h&g ...
随机推荐
- idea配置阿里maven镜像
首先打开IDEA安装路径下的:"\plugins\maven\lib\maven3\conf\settings.xml" 找到里面的mirror配置,进行修改如下: <mir ...
- EF多个表映射
public class Media // One entity table { public int Id { get; set; } public string Name { get; set; ...
- Redis集群简介及部署
1简介 在 Redis 3.0 之前,使用 哨兵(sentinel)机制来监控各个节点之间的状态.Redis Cluster 是 Redis 的 分布式解决方案,在 3.0 版本正式推出,有效地解决了 ...
- ubuntu系统共享桌面的使用和配置
内容转载自我的博客 目录 1. ubuntu共享桌面 2. 局域网登录远程桌面 2.1 ubuntu使用remmina登录远程桌面 2.2 在windows登录远程桌面 2.3 Android使用RD ...
- 如何实现一个简易版的 Spring - 如何实现 @Autowired 注解
前言 本文是 如何实现一个简易版的 Spring 系列第四篇,在 上篇 介绍了 @Component 注解的实现,这篇再来看看在使用 Spring 框架开发中常用的 @Autowired 注入要如何实 ...
- cve-2019-2725 反序列化远程代码执行
描述:部分版本WebLogic中默认包含的wls9_async_response包,为WebLogic Server提供异步通讯服务.由于该WAR包在反序列化处理输入信息时存在缺陷,攻击者可以发送精心 ...
- 一个mac软件合集的网站
https://github.com/jaywcjlove/awesome-mac/blob/master/README-zh.md
- JMeter扩展Java请求实现WebRTC本地音视频推流压测脚本
WebRTC是Web Real-Time Communication缩写,指网页即时通讯,是一个支持Web浏览器进行实时语音或视频对话的API,实现了基于网页的视频会议,比如声网的Agora Web ...
- 滑动窗口解决最小子串问题 leetcode3. Longest Substring Without Repeating Characters
问题描述: Given a string, find the length of the longest substring without repeating characters. Example ...
- python 画图中文显示问题
在python文件当前目录下添加simsun.ttc(资源网上下载即可,有很多) 代码如下: plt.title("标题", fontproperties='SimHei', si ...