//采用map容器即可,由于map容器的底层原理是红黑树(linux系统,windows为平衡二叉搜索树),所以查找起来很快 #include "stdio.h" #include "map" #include "string" using namespace std; int main(){ int n; scanf("%d",&n); map<string ,string> myMap; char stuFormation[20];char number[10]; for (int i = 0; i < n; ++i) { scanf("%s",number); fgets(stuFormation,20,stdin); string str = stuFormation;str.pop_back(); myMap.insert(pair<string,string>(number,str)); } int search; scanf("%d",&search); for (int i = 0; i < search; ++i) { scanf("%s",number); map<string,string> :: iterator it = myMap.find(number); if(it != myMap.end()){ printf("%s%s\n",it->first.c_str(),it->second.c_str()); } else{ printf("No Answer!\n"); } } }