uva 10391 Compound Words <set>
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 theconcatenation 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, inalphabetical order.
Sample Input
a
alien
born
less
lien
never
nevertheless
new
newborn
the
zebra
Sample Output
alien
newborn 用set做
#include <iostream>
#include <set>
#include <string>
using namespace std; set<string>dic;
set<string>::iterator t; int main()
{
string word;
while(cin >> word)dic.insert(word); for(t = dic.begin(); t != dic.end(); t++){
word = *t;
int n = word.length(); for(int i = ; i < n - ; i++ ){
string s1=word.substr(,i+),s2 = word.substr(i+,n-i-);
if( (dic.count(s1)) && (dic.count(s2)) ){
cout << word <<endl;
break;
}
}
}
//system("pause");
return ;
}
dic.count(s2) 在set dic中计算s2的个数,并返回其个数。
uva 10391 Compound Words <set>的更多相关文章
- 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 ...
- 复合词(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 ...
- Compound Words UVA - 10391
You are to find all the two-word compound words in a dictionary. A two-word compound word is a wor ...
- UVa 10391 (水题 STL) Compound Words
今天下午略感无聊啊,切点水题打发打发时间,=_=|| 把所有字符串插入到一个set中去,然后对于每个字符串S,枚举所有可能的拆分组合S = A + B,看看A和B是否都在set中,是的话说明S就是一个 ...
- 【UVA】10391 Compound Words(STL map)
题目 题目 分析 自认已经很简洁了,虽说牺牲了一些效率 代码 #include <bits/stdc++.h> using namespace std; 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> ...
随机推荐
- (转) Resource file and Source file
基本上是这样的,Sourcefile文件夹里面放的是CPP文件这些,Resourcefile文件夹是资源文件夹,里面可以放你程序里需要的资源,包括图标,对话框,图片等等:对应的文件如下: Source ...
- android 开发中判断网络是否连接的代码
在android的开发中,尤其是与访问网络有关的开发,都要判断一下手机是否连接上了网络,下面是一个判断是否连接网络的嗲吗片段: package cn.com.karl.util; import com ...
- MyISAM 存储引擎
在MYSQL 5.1 以及之前的版本,MyISAM 是默认的存储引擎.MyISAM 提供了大量的特性,包括全文索引,压缩,空间函数(gis)等,但是MyISAM不支持事务和行级锁,而且有一个毫无疑问的 ...
- 网上查了点关于windows注册表的知识,发现基本名词没理解好,于是整理这篇笔记(可能个别地方不准确,先这么理解吧),有了这个理解,再去看网上的文章,就差不读了
打开注册表编辑器,左边窗格中显示的是“注册表项”,右边窗格中显示的是“注册表项的项值” 子项:子项是相对父项而言的,在某一个项(父项)下面出现的项(子项) 值项:一个项可以有一个或多个项值,当前被使用 ...
- OAuth 2.0 开发完全详解
--------------------------基础篇------------------------------- I:OAuth 2.0 概述 首先大家来看看国内新浪跟腾讯这两大头对OAuth ...
- 通过jstack定位在线运行java系统故障_案例1
问题描述: 在一个在线运行的java web系统中,会定时运行一个FTP上传的任务,结果有一天发现,文件正常生成后却没有上传. 问题初步分析: 1.查看日志文件 发现这个任务只打印了开始进入FTP处理 ...
- c++ 12
一.模板与继承 1.从模板类派生模板子类 2.为模板子类提供基类 二.容器和迭代器 以链表为例. 三.STL概览 1.十大容器 1)向量(vector):连续内存,后端压弹,插删低效 2)列表(lis ...
- hdu 1829 A Bug's Life(并查集)
A Bu ...
- c++中经常需要访问对象中的成员的三种方式
可以有3种方法: 通过对象名和成员运算符访问对象中的成员; 通过指向对象的指针访问对象中的成员; 通过对象的引用变量访问对象中的成员. 一.通过对象名和成员运算符访问对象中的成员 例如在程序中可以写出 ...
- C++ I/O标准库
C++学习: 返回指向函数的指针: int (*ff(int))(int *,int) 想写好这样的代码很难,含义:首先将ff声明为一个函数,它带有一个int形参.该函数返回 int (*)(int* ...