poj2503 Barbelfish

2024-06-17 03:48
文章标签 poj2503 barbelfish

本文主要是介绍poj2503 Barbelfish,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

题目是水题,用STL的map做,处理空行很有技巧

代码如下

下面这段会CE,原因是

#include <iostream>
using namespace std;
#include <cstdlib>
#include <cstdio>
#include <string.h>
#include <map>
map<string,bool>appear;
map<string,string>dic;
int main()
{char english[11],foreign[11];while(true){char t;if((t=getchar())=='\n')break;else{english[0]=t;int i=1;while(true){t=getchar();if(t==' '){english[i]='\0';break;}elseenglish[i++]=t;}}cin>>foreign;getchar();appear[foreign]=true;//这里会CE,应该用个string中转一下。而且我又犯糊涂了,调整后又把编译器弄成GCC,然后无限CE = =dic[foreign]=english;}char word[11];while(cin>>word){if(appear[word])cout<<dic[word]<<endl;elsecout<<"eh"<<endl;}return 0;
}


#include <iostream>
#include <string>
#include <map>
#include <stdio.h>
using namespace std;
int main()
{char english[11],foreign[11];map<string,bool>appear;map<string,string>dic;while(true){char t;if((t=getchar())=='\n')break;else{english[0]=t;int i=1;while(true){t=getchar();if(t==' '){english[i]='\0';break;}elseenglish[i++]=t;}}cin>>foreign;getchar();string strfo=foreign;string stren=english;appear[strfo]=true;dic[strfo]=stren;}string word;while(cin>>word){if(appear[word])cout<<dic[word]<<endl;elsecout<<"eh"<<endl;}return 0;
}


这篇关于poj2503 Barbelfish的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1068404

相关文章

POJ2503_Babelfish(字典树)

Babelfish Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 You have just moved from Waterloo to a big city. The people here speak an incomprehensible dialect of a foreign langua

poj2503 Babelfish BKDRhash+链式hash

题目链接 题意:给定字符串以及对应的字符串,再给字符串找到对应的字符串,不存在输出"eh"。 思路:造模板。 /*********************************************************file name: poj2503.cppauthor : kereocreate time: 2015年04月12日 星期日 17时13分12秒*******

poj2503 Babelfish

#include<iostream>#include<cstring>#include<string>#include<map>#include<cstdio>using namespace std;char english[12],foreign[12];int main(){map<string,bool>appear; //记录foreign与engliash的配对映射是