uva 10391 Compound Words <set>
2016-05-10 12:58
531 查看
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.
dic.count(s2) 在set dic中计算s2的个数,并返回其个数。
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 = 0; i < n - 1; i++ ){ string s1=word.substr(0,i+1),s2 = word.substr(i+1,n-i-1); if( (dic.count(s1)) && (dic.count(s2)) ){ cout << word <<endl; break; } } } //system("pause"); return 0; }
dic.count(s2) 在set dic中计算s2的个数,并返回其个数。
相关文章推荐
- matlab用循环批量生成多个变量,神奇的eval()函数
- 【SSH网上商城项目实战09】添加和更新商品类别功能的实现
- 八爪鱼招标网的百度权重升为2了,独立IP也从0快速发展为1000
- iOS开发添加Reveal工具
- Unix网络编程之UDP实例
- 每秒处理10万订单乐视集团支付架构
- Java中,当表单含有文件上传时,提交数据的如何读取
- System::String *,char*,string 等的类型转换 [转]
- C 数组
- 弱指针
- 渗透测试一些思路分享
- 为韩春雨老师和他的 NgAgo-gDNA 点赞
- 为韩春雨老师和他的 NgAgo-gDNA 点赞
- SAX解析XML文件
- 我的世界:8分钟教会你开服联机
- 第十一周阅读程序(5.1)
- hive开启严格模式
- Spring 4.x Reference翻译(一)IOC容器
- mysql DDL时出现的锁等待状态
- 机器数据的价值 - Web 访问日志和数据库审计日志