uva 10391 compound words
来源:互联网 发布:淘宝有快排吹 编辑:程序博客网 时间:2024/06/07 08:07
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
题解:看是否有一个单词是由其他两个单词构成的。用string.substr(a,b)//始a,终b 来拆分string,再来寻找。
#include <iostream>#include <set>#include <cstdio>#include <string>using namespace std;set <string> v;//set容器int main(){ string st; set <string>::iterator p;//迭代器 while(cin>>st) v.insert(st); for(p=v.begin(); p!=v.end(); p++) { st=*p; for(int i=0; i<st.length()-1; i++) { string sub1=st.substr(0,i+1);//拆分string,再去寻找 string sub2=st.substr(i+1,st.length()-(i+1)); if( v.find(sub1)!=v.end() && v.find(sub2 )!=v.end() )//查找 { printf("%s\n",st.c_str());//将string用%s输出 break; } } } return 0;}uva :原题链接
国内链接:https://vjudge.net/contest/169852#problem/E
阅读全文
0 0
- uva 10391 compound words
- UVa 10391 - Compound Words
- uva 10391 - Compound Words
- uva 10391 - Compound Words
- UVa 10391 - Compound Words
- UVa 10391 - Compound Words
- uva 10391 - Compound Words
- UVA 10391 Compound Words
- UVA 10391 - Compound Words
- Uva-10391-Compound Words
- UVa 10391 - Compound Words
- uva--10391 - Compound Words
- UVA 10391 Compound Words
- UVa:10391 Compound Words
- uva 10391 Compound Words
- UVa 10391 - Compound Words
- UVA 10391 Compound Words
- UVA 10391 - Compound Words
- eclipse 项目导入android studio 各类问题及解决方法
- 固态硬盘(samsung SSD 850 pro)相关问题
- Visual studio 2013 连接MySQL数据库的设置
- java中RSA加解密的实现
- 用Spark 2.2中的结构化流API处理Kafka数据-端到端
- uva 10391 compound words
- java语言实现图的深度优先遍历
- Javascript实现继承的方法
- 是用mina自定义解析器
- 一些框架的总结
- Spring Data JPA基础使用
- 新安装的Myeclipse创建新项目Configure build path
- 计算机基础——码制表示
- 问题集