You are to find all the two-word compound words in a dictionary. A two-word compound word is a word
2015-12-06 18:09
696 查看
//自己不会写 但是看懂了学长写的
#include <iostream>
#include <string> //string类
#include <map>
using namespace std;
int main()
{
map<string,bool>hash;//hash散列 我发现把hash改成别的也对
string str[150000];
hash.clear(); //清空hash
string temp;
string a,b;
int num=0;
while(cin>>str[num]) //输入str
{
hash[str[num]]=true;
num++;
}
// num 输入的单词个数
for(int i=0;i<num;i++)
{
temp=str[i]; //temp 为第一个 第二个 第三个 ......单词
for(int j=0;j<temp.size()-1;j++)//加1 是为了防止越界
{
a=temp.substr(0,j+1); //a 是第一个 第二个 第三个 ......单词从第一个字母到第j+1个字母
b=temp.substr(j+1); //b 是第一个 第二个 第三个 ......单词从第j+1个字母直到最后
if(hash[a]&&hash[b]) //如果 输入的单词中有 a 又有 b
{
cout<<temp<<endl; //那么输出temp
break;
}
}
}
return 0; //hahaha ok啦
}
#include <iostream>
#include <string> //string类
#include <map>
using namespace std;
int main()
{
map<string,bool>hash;//hash散列 我发现把hash改成别的也对
string str[150000];
hash.clear(); //清空hash
string temp;
string a,b;
int num=0;
while(cin>>str[num]) //输入str
{
hash[str[num]]=true;
num++;
}
// num 输入的单词个数
for(int i=0;i<num;i++)
{
temp=str[i]; //temp 为第一个 第二个 第三个 ......单词
for(int j=0;j<temp.size()-1;j++)//加1 是为了防止越界
{
a=temp.substr(0,j+1); //a 是第一个 第二个 第三个 ......单词从第一个字母到第j+1个字母
b=temp.substr(j+1); //b 是第一个 第二个 第三个 ......单词从第j+1个字母直到最后
if(hash[a]&&hash[b]) //如果 输入的单词中有 a 又有 b
{
cout<<temp<<endl; //那么输出temp
break;
}
}
}
return 0; //hahaha ok啦
}
相关文章推荐
- keepalived配置基于lvs DR模型的HA
- 对kalman滤波的理解
- Python基础教程读书笔记
- Android 数据库SQL增、删、查、改
- 用python抢火车票
- 解决tomcat的startup.bat开启闪退问题
- 二叉树与树、森林之间的转换
- B树的实现算法
- android错误详细教程四
- 题解: Codeforces 598A Tricky Sum (水)
- Cocos2d3.0学习笔记-Action复杂动作
- Android开发日记(五)
- js array.length 问题
- Apache mina VS Netty
- 二叉树的实现
- a new beginning
- 【Android】屏幕像素、密度工具类
- Java API —— BigDecimal类
- Xcode插件
- [CodeVS1036] 商务旅行