紫书第五章训练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,即可在对应版本中使用. 计算机视觉这章分为两 ...
随机推荐
- BS3 多级菜单
<div class="container"> <div class="row"> <h2>Multi level drop ...
- 前端之CSS列表及背景类属性
一.列表类属性: 1.列表符号样式: list-style-type:disc(实心圆)|circle(空心圆)|square(实心方块)|decimal(数字)|none(去掉列表符号样式); 2. ...
- Java编程基础-面向对象(下)
一.抽象类 1.引入:当定义一个类时,常常需要定义一些方法来描述该类的行为特征,但有时这些方法的实现方式是无法确定的.Java允许在定义方法时不写方法体,不包含方法体的方法为抽象方法,抽象方法必须使用 ...
- google kickstart 2018 round D A Candies
思路: 对于small数据,由于求和及奇数数量两个限制条件均满足区间单调性,可以直接使用尺取法(滑动窗口法)求解. 对于large数据,奇数数量依然是满足区间单调性的.首先使用尺取法,找到所有满足奇数 ...
- js图片预加载以及延迟加载
当我们需要做图片轮播的时候,如果让图片提前下载到本地,用浏览器缓存起来,我们可以用Image对象: function preLoadImg(){ var img=new Image(); img.sr ...
- codewars遇到的比较有意思的题目
题目要求是编写一个函数用来检测一个字符串,字符串是一系列单词组成,每个单词间用空格隔开,不用考虑空字符串的情况,返回长度最小的那个单词的长度. 博主刚入门PHP,技术还很菜,没有想出来,看了其他人的解 ...
- Oracle数据仓库创建教程
Oracle数据仓库创建教程.如何创建一个数据仓库,创建实例,以为毕业设计要求,最近开始Oracle的数仓建模实践,详细记录了图形界面下的 Oracle database 12C 数据仓库创建过程. ...
- Android adb命令,linux中各种命令
常用的ADB命令 1. 显示系统中全部Android平台: android list targets 2. 显示系统中全部AVD(模拟器): android list avd 3. 创建AVD(模拟器 ...
- Yii2.0 Cookies机制和使用方法
在实际的项目开发过程中,用到了Yii2.0 Cookies机制!但是遇到一个十分奇葩的问题,同一个YII框架,backend下Cookies能够正常存储于客户端,但是frontend始终不行.文章的最 ...
- LR中排序脚本
/* * LoadRunner Java script. (Build: 670) * * Script Description: * */ import lrapi.lr; public class ...