[二分查找]Compound Words uva10391
来源:互联网 发布:ipad 软件 编辑:程序博客网 时间:2024/06/04 19:19
Problem E: 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
aalienbornlesslienneverneverthelessnewnewbornthezebra
Sample Output
aliennewborn
题意:给出一系列单词,找出由其中两个单词复合组成的单词。直接排序然后二分查找了。
#include<iostream>#include<string>#include<algorithm>using namespace std;int k;string st[120005];bool cmp(string x,string y){ return x<y;}int search(string str){ int left=0,right=k-1,mid; while(left<=right) { mid=(left+right)/2; if(st[mid]<str) { left=mid+1; } else if(st[mid]>str) { right=mid-1; } else return 1; } return 0;}int main(){ string str; int i,j; k=0; while(getline(cin,str)) { st[k++]=str; } sort(st,st+k,cmp); //cout<<k<<endl; for(i=0;i<k;i++) { for(j=1;j<st[i].size()-1;j++) { string str1(st[i],0,j); string str2(st[i],j,(st[i].size()-j)); if(search(str1)&&search(str2)) { cout<<st[i]<<endl; break; } } } return 0;}
1 1
- [二分查找]Compound Words uva10391
- uva10391 - Compound Words
- UVA10391- Compound Words
- UVa10391 - Compound Words
- UVa10391 - Compound Words
- UVA10391 Compound Words
- UVA10391:Compound Words(复合词)
- [UVA10391]Compound Words[map][实现]
- UVa10391-- Compound Words(字符串hash)
- Uva10391 Compound Words 【俩方法:1.二分;2.set集合】【习题5-5】
- UVA10391 ZOJ1825 Compound Words【SET+暴力】
- uva10391 Compound Words (substr用法)
- uva 10391 Compound Words(查找)
- uva10391 单词复合 利用二分查找求解
- [刷题]算法竞赛入门经典(第2版) 5-5/UVa10391 - Compound Words
- 算法竞赛入门经典 第二版 习题5-5 复合词 Compound Words uva10391
- UVa 10391 Compound Words(字符串+查找)
- Compound Words
- 循环赛日程表问题
- 【机器学习笔记】一、Supervised learning监督学习
- 2047——阿牛的EOF羊肉串
- tigerVNC的简单使用教程(CentOS的远程桌面连接)
- 新人刚入职场如何做到让人刮目相看!
- [二分查找]Compound Words uva10391
- 创建目录函数
- tdd开发学习
- Hibernate 学习总结
- CF - 389 - B. Fox and Cross(贪心)
- jquery mobile alter、confirm重写,使用popup
- hdu 1004 翻译
- www.id666.com中的免费空间
- JavaScript入门之基本语法