哈希表查询编号

代码:

#include<iostream>
#include<map>
using namespace std;
struct stu{
    string id,name,sex;
    int age;
}s[1005];
int cnt;
int main(){
    ios::sync_with_stdio(false);
    int n,m;
    while(cin>>n){
        map<string,int>mp;
        cnt=0;
        for(int i=1;i<=n;++i){
            cin>>s[++cnt].id>>s[cnt].name>>s[cnt].sex>>s[cnt].age;
            mp[s[cnt].id]=cnt;
        }
        cin>>m;
        string qs;
        int idx;
        for(int i=1;i<=m;++i){
            cin>>qs;
            auto t=mp.find(qs);
            if(t!=mp.end()){
                idx=(*t).second;
    cout<<s[idx].id<<" "<<s[idx].name<<" "<<s[idx].sex<<" "<<s[idx].age<<endl;
            }else{
                cout<<"No Answer!"<<endl;
            }
           
        }
    }
    return 0;
}