映射关系

  • 整行读取getline(cin,s)
  • 读走换行符getchar()
#include<iostream>
#include<string>
#include<map>
using namespace std;

int main(){
  int n;
  while(scanf("%d",&n)!=EOF){
    getchar();//读走换行符
    map<string,string>mymap;
    string s;
    while(n--){
      getline(cin,s);
      int pos=s.find(" ");//编号部分长度
      mymap[s.substr(0,pos)]=s;
    }
    
    int m;
    scanf("%d",&m);
    string key;
    while(m--){//查询
      cin>>key;
      string ans=mymap[key];
      if(ans=="")printf("No Answer!\n");
      else cout<<ans<<endl;
    }
  }
  return 0;
}