UVA 10391Compound Words 用set实现
来源:互联网 发布:ios10下载bt软件 编辑:程序博客网 时间:2024/06/10 19:23
题目:UVA 10391 Compound Words
https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=836&page=show_problem&problem=1332
简单题意:查找复合词,输入一个字典,输出可以由两个单词复合而成的单词,最多120000个单词;
解题思路形成过程:
开始想写 双重循环,但是题目数据太大,即使用set 也可能会超时,就只能用一次循环,分割每个单词,分割单词后 查找分割出的两个单词在不在set 中,在的话存入另一个集合;
感想:虽然题目不难,但是打代码的时候少了个“2”,检查了好大一会才找出错误,所以写的时候要认真,检查也要好好检查;
AC代码:
#include <iostream>
#include <string>
#include <set>
using namespace std;
string s1,s2,s,ss;
void fenge(string s,int n)//分割单词
{
s1 = "";
s2 = s;
for(int i = 0;i < n;i++)
{
s1 += s2[0];
s2.erase(0,1);
//cout<<s1<<"**"<<s2<<endl;
}
}
int main()
{
int i;
set<string>se_1,se_2;
set<string>::iterator it,itt;
while(cin>>ss)
se_1.insert(ss);
for(it = se_1.begin();it != se_1.end();it++)//分割每个单词后 查找分割出的两个单词在不在set中;
{
s = *it;
for(i = 0; i < s.size() - 1;i++)
{
fenge(s,i);
if(se_1.find(s1) != se_1.end() && se_1.find(s2) != se_1.end())
{
se_2.insert(s);
}
}
}
for(itt = se_2.begin();itt != se_2.end();itt++)
{
cout<<*itt<<endl;
}
return 0;
}
- UVA 10391Compound Words 用set实现
- UVA - 10391 Compound Words 迭代器和set
- 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
- C++第一次实验+1
- [LeetCode] Single Number & Single Number III
- JVM学习笔记(四)之类加载机制
- 记一次eclipse到android studio 的项目迁移记录
- 多项分布与Direchlet分布
- UVA 10391Compound Words 用set实现
- 登录校园网用的bash脚本
- Topic Model 都有哪些
- poj 1182 食物链(并查集)(并查集模板)
- C++第一次实验-1
- 编译openwrt记录
- java配置opencv-在eclipse中
- 文章标题
- 跟踪分析Linux内核的启动过程