UVA 10391(把符合单词输出,map)
来源:互联网 发布:华夏名网域名注册 编辑:程序博客网 时间:2024/06/06 14:12
Compound Words
Time Limit: 3000ms Memory Limit: 131072KB
[PDF Link]
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<cstdio>#include<string>#include<map>using namespace std;const int maxn = 120010;string str[maxn],str1,str2;map <string,int> mymap;int r = 0;void input(){ while(cin>>str[r++]){ mymap[str[r-1]]=2;//也可以为别的数 }}void solve(){ for(int i=0;i<r;i++){ str1.clear(); str2.clear(); for(int j=0;j<str[i].length();j++){ str1+=str[i][j]; if(mymap[str1]==2){ str2=&str[i][j+1]; if(mymap[str2]==2){ cout<<str[i]<<endl; break; } } } }}int main(){ input(); solve(); return 0;}
0 0
- UVA 10391(把符合单词输出,map)
- UVA 156 筛选不重复单词, map
- Ananagrams (uva 156,bnu 17295) map用法,单词标准化
- 输出迭代器 ostream_iterator 把输入的一串字符按每行一个单词输出
- choose the longest word in the line .把字符串中最长的单词输出
- 输入一个字符串,把这个字符串中的每个单词打印出来,即输出到屏幕
- UVA 156-Ananagrams(字符串排序按序输出无重复单词)
- 单词转换(stl map)
- 单词数+map
- 统计单词频率-map
- 一个字符串去除里面的数字,把剩下的字符输出 和 一个字符串计算最大单词的长度并输出这个单词
- UVA 10129 单词
- UVa 10129 单词
- uva 10129 单词
- UVa-10129 单词
- 【Uva 10129】玩弄单词
- uva-10129 单词
- 逆序输出单词
- 最值得关注的10个C开源项目之Webbench源码分析
- The Data Scientist Guide with Links
- 第三章Linux网络基础编程
- Ubuntu12.04下的Redmine安装和数据库迁移恢复
- UML实战总结——机房收费系统UML第一版部分图展
- UVA 10391(把符合单词输出,map)
- Android 图片OutOfMemory异常bitmap size exceeds VM budget的原因及解决方法
- jquery实现鼠标滑过 table 行变色
- bootstrap可视化布局可以得到纯html的布局div,直接使用
- C++ primer 学习笔记(一)
- Ubuntu启动进入initramfs模式的解决办法
- form表单提交的几种方法
- register_chrdev_region && alloc_chrdev_region
- Android 音频 OpenSL ES 录音