POJ - 2503 Babelfish
https://vjudge.net/problem/POJ-2503
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
int main()
{
ios::sync_with_stdio(false); //用cin要关闭同步不然超时
cin.tie(0); cout.tie(0);
string s,a,b;
map<string,string>x;
while(getline(cin,s))
{
int l=s.size();
if(l==0) break;
int t=s.find(" ");
a=s.substr(0,t);
b=s.substr(t+1,l-t-1);
x[b]=a;
}
while(cin>>s)
{
if(!x[s].empty())
cout<<x[s]<<"\n";
else cout<<"eh\n";
}
return 0;
}
#include<iostream>
#include<algorithm>
#include<map>
#include<cstring>
#include<cstdio>
using namespace std;
int main()
{
char s[110];
int t;
map<string,string> q;
while( gets(s) && strlen(s)!=0) //用gets记得加上cstdi头文件
{
char a[15],b[15];
int i,j;
for(i=0;s[i]!=' ';i++)
a[i]=s[i];
a[i]='\0'; //这里一定要加结束符 不然要是第二个串比第一个短,第二个串的存储就会出错,后边有一部分是第一个串的
i++;
for(j=0;i<strlen(s);i++,j++)
b[j]=s[i];
b[j]='\0';
q[b]=a;
}
while(gets(s))
{
if(q.find(s)!=q.end())
cout<<q[s]<<"\n";
else
cout<<"eh\n";
}
return 0;
}
#include<cstdio>
#include<map>
#include<iostream>
using namespace std;
map<string,string>x;
int main(void)
{
char a[100],b[50],c[50];
while(gets(a)&&a[0]!='\0')
{
sscanf(a,"%s %s",b,c);//输入格式
x[c]=b;
}
while(gets(a))
{
if(x.find(a)!=x.end())
cout<<x[a]<<endl;
else
cout<<"eh"<<endl;
}
return 0;
}
本文来自博客园,作者:斯文~,转载请注明原文链接:https://www.cnblogs.com/zhiweb/p/15483261.html

浙公网安备 33010602011771号