UVA 10391 Compound Words
来源:互联网 发布:网店美工培训课程 编辑:程序博客网 时间:2024/06/03 16:52
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
aalienbornlesslienneverneverthelessnewnewbornthezebra
Sample Output
aliennewborn
思路:
两种思路,合成和拆分。前者时间复杂度为O(n^2),超时。后者的为O(n*m),m小于n,VJ50ms,AC。
#include <iostream>#include <cstdlib>#include <string>#include <map>using namespace std;const int maxn=120000+5;int main(){ string word[maxn]; map<string,bool> jud; int cnt=0; while(cin>>word[cnt]) jud[word[cnt++]]=true; for(int i=0;i<cnt;i++) for(int j=0;j<(int)word[i].size()-1;j++) { string a=word[i].substr(0,j+1); if(!jud[a]) continue; string b=word[i].substr(j+1); if(!jud[b]) continue; cout<<word[i]<<endl; break; } return 0;}
阅读全文
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
- 文件操作fstream的使用方法
- 读《大学之路》下册
- zookeeper管理数据库连接信息
- 学习JavaScript数据结构与算法(三)——队列
- spring boot 集成quartz集群
- UVA 10391 Compound Words
- python连接mysql(PyMySQL)
- phpredis中文手册
- Java多线程之CountDownLatch的使用
- 151. Reverse Words in a String
- 【C++】类和对象
- 顺序表——学生成绩管理
- hdoj-1016 Prime Ring Problem
- .cvs文件读取转成对象