题意:读入两组数据,如果第二个的对应的是第一个,那就输出对应的字符串,否则输出eh.
无线次的输入时候可以先用gets,gets从标准输入设备读字符串函数。可以无限读取,不会判断上限,以回车结束读取。
读入到一个数据流中,然后用sscanf读出。进行判断。如果没有的话,对应 的map【b】 == “\0”;
#include<iostream>
#include<stdio.h>
#include<map>
#include<string>
#include<string.h>
using namespace std;
int main()
{
char s[100];
char a[100],b[100];
char str[100];
map<string,string>m;
while(gets(s)&& s[0]!='\0')
{
sscanf(s,"%s%s",a,b);
m[b] = a;
}
while(gets(s)&&s[0]!='\0')
{
sscanf(s,"%s",str);
if(m[str]!="\0")
cout<<m[str]<<endl;
else cout<<"eh"<<endl;
}
return 0;
}