UVA-10391 二分
来源:互联网 发布:流程图绘制软件 编辑:程序博客网 时间:2024/06/07 07:38
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
题意: 找出所有满足其是由其他两个单词组成的单词。
思路:二分找一个单词的前后两个部分是否是字典中的单词。
#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; }
阅读全文
0 0
- UVA-10391 二分
- uva 1450 - Airport(二分)
- UVa 2678 Subsequence / 二分
- uva 12097 二分
- Number Sequence uva+二分
- Flooded! - UVa 815 二分
- uva 11129(二分)
- uva--10341+二分
- uva 12097(二分)
- uva 1421 箭术 (二分)
- UVA - 11627 Slalom 二分
- uva 11627(二分)
- uva 10341 二分搜索
- uva 10566 二分
- UVA 11090 图论加二分
- uva 1443 dp+二分
- uva 1371 dp+二分
- UVA 12124 Assemble(二分)
- Git的基本操作
- 猜数游戏的一个C++实现
- SSM(SpringMVC Spring Mybatis)三大框架从零开始搭建实例
- c# 控件多屏显示全屏功能
- 如何在软件UI设计中运用格式塔心理学5项法则?
- UVA-10391 二分
- 关于.NET 垃圾回收机制
- 机器学习学习笔记 2、概率论
- RecyclerView嵌套RecyclerView
- Spring AOP详解(示例)
- JavaNIO的系列教程
- 收视率一直是门玄学,但有人把它变成了科学
- mysql经典查询练习
- Python学习随笔一:数据类型和字符编码