紫书第五章训练2 F - Compound Words
F - 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 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
这个题就是找个单词是已出现两个单词的和,我用map写一直错, 我分析了下大概是每次都要访问map,然后map的空间就不够了,所以还是用set搞下不错,他和map的查询复杂度都是logn的,运用string还有find岂不是很简单实用,美滋滋
不过需要提出的是字典树或者直接数组搞会比stl速度快些的
#include <bits/stdc++.h>
using namespace std;
int main(){
string s;
set<string>ma;
while(cin>>s){
ma.insert(s);
}
set<string>::iterator it;
for(it=ma.begin();it!=ma.end();it++){
string c=*it;
for(int i=;c[i];i++){
if(ma.find(c.substr(,i))!=ma.end()&&ma.find(c.substr(i))!=ma.end()){
cout<<c<<endl;
break;
}
}
} return ;}
紫书第五章训练2 F - Compound Words的更多相关文章
- 紫书第五章训练3 D - Throwing cards away I
D - Throwing cards away I Given is an ordered deck of n cards numbered 1 to n with card 1 at the top ...
- 紫书第三章训练1 D - Crossword Answers
A crossword puzzle consists of a rectangular grid of black and white squares and two lists of defini ...
- 紫书第三章训练1 E - DNA Consensus String
DNA (Deoxyribonucleic Acid) is the molecule which contains the genetic instructions. It consists of ...
- GAN实战笔记——第五章训练与普遍挑战:为成功而GAN
训练与普遍挑战:为成功而GAN 一.评估 回顾一下第1章中伪造达・芬奇画作的类比.假设一个伪造者(生成器)正在试图模仿达・芬奇,想使这幅伪造的画被展览接收.伪造者要与艺术评论家(判别器)竞争,后者试图 ...
- OpenGL蓝宝书第五章代码勘误以及惯性坐标系去解释模型变换:Pyramid.cpp
假设你也发现依照教程代码完毕贴图时,你会底面的坐标和寻常顶点坐标正负相反,比方-1.0f, -1.0f, -1.0f这个顶点相应的却是世界坐标中1.0f,-1.0f,1.0f 问题到底出如今哪里? 原 ...
- 紫书第5章 C++STL
例题 例题5-1 大理石在哪儿(Where is the Marble?,Uva 10474) 主要是熟悉一下sort和lower_bound的用法 关于lower_bound: http://blo ...
- 小红书第五章——引用类型之function类型
有趣的函数——function类型 函数实际上是对象,每个函数都是function类型的实例,具有属性和方法. 1.函数的定义方法 1)函数声明语法 function sum(num1,num2){/ ...
- 《汇编语言 基于x86处理器》前五章的小程序
▶ 书中前五章的几个小程序,基本的运算操作,使用了作者的库 Irvine32 和 Irvine64(一开始以为作者网站过期了,各网站上找到的文件大小都不一样,最后发现是要搭梯子 Orz,顺利下载).注 ...
- ROS机器人程序设计(原书第2版)补充资料 (伍) 第五章 计算机视觉
ROS机器人程序设计(原书第2版)补充资料 (伍) 第五章 计算机视觉 书中,大部分出现hydro的地方,直接替换为indigo或jade或kinetic,即可在对应版本中使用. 计算机视觉这章分为两 ...
随机推荐
- javascript for/forEach
基本用法 for:for(var i=0;i<arr.length;i++) forEach:arr.forEach(function(value,index,arr){},),其中functi ...
- 洛谷 P2419 [USACO08JAN]牛大赛Cow Contest
题目背景 [Usaco2008 Jan] 题目描述 N (1 ≤ N ≤ 100) cows, conveniently numbered 1..N, are participating in a p ...
- P2421 A-B数对(增强版)
题目背景 woshiren在洛谷刷题,感觉第一题:求两数的和(A+B Problem)太无聊了,于是增加了一题:A-B Problem,难倒了一群小朋友,哈哈. 题目描述 给出N 个从小到大排好序的整 ...
- html与css入门经典视频教程 千锋说要这样学
PHP初学者看过来,老师带来的PHP入门经典视频教程,带你轻松入门,学习PHP就是这么简单. 很多人不理解为什么学习PHP要先学习HTML基础和CSS,其实PHP作为服务器的脚本语言,在开发过程中用于 ...
- spring_boot入门
核心: 控制反转(Inversion of Control-IOC)和依赖注入(Dependency Injection-DI) Spring中两者是相同的, 控制反转是用依赖注入实现的. 这里, 依 ...
- Entity Framework插入数据报错:Validation failed for one or more entities
www.111cn.net 编辑:lanve 来源:转载 今天在处理Entity Framework插入数据库时,报错: Validation failed for one or more entit ...
- 图像处理框架 Core Image 介绍
这篇文章会为初学者介绍一下 Core Image,一个 OS X 和 iOS 的图像处理框架. 如果你想跟着本文中的代码学习,你可以在 GitHub 上下载示例工程.示例工程是一个 iOS 应用程序, ...
- js设置元素float的问题
用js设置一个元素的float样式 div.style.float = 'left'; 这句话在谷歌浏览器或许没问题,但是在IE,火狐下会无效 正确写法是 div.style.styleFloat = ...
- 一张图看懂苹果MacBook所有屏幕分辨率
苹果全新12寸超薄MacBook比曾经最薄的MacBook Air更薄,不过却配备了Retina视网膜显示屏.12英寸RetinaMacBook上的显示屏分辨率为2304*1440,虽然不如15寸和1 ...
- eclipse 在写XML时 包类名自动提醒的问题
需要加一个STS插件 配置很简单 参考了 https://blog.csdn.net/HH775313602/article/details/70176531 在 https://spring.io ...