关键:map和set结合使用
#define LOCAL
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
using namespace std;
map<string,set<int> > mpTitle,mpAuthor,mpKey,mpPub,mpYear;
void query(map<string,set<int> >& mp,string& str){
if(mp.find(str)==mp.end()) printf("Not Found\n");
else{
for(set<int>::iterator it=mp[str].begin();it!=mp[str].end();it++){
printf("%07d\n",*it);
}
}
}
int main()
{
#ifdef LOCAL
freopen("data.in","r",stdin);
freopen("data.out","w",stdout);
#endif // LOCAL
int n;int id;
scanf("%d",&n);
string title,author,key,pub,year;
for(int i=0;i<n;i++){
scanf("%d",&id);
char c=getchar();
getline(cin,title);
mpTitle[title].insert(id);
getline(cin,author);
mpAuthor[author].insert(id);
while(cin>>key){
mpKey[key].insert(id);
c=getchar();
if(c=='\n')break;
}
getline(cin,pub);
mpPub[pub].insert(id);
getline(cin,year);
mpYear[year].insert(id);
}
string t;
int m;
int q;
scanf("%d",&m);
while(m--){
scanf("%d: ",&q);
getline(cin,t);
cout<<q<<": "<<t<<endl;
if(q==1) query(mpTitle,t);
else if(q==2) query(mpAuthor,t);
else if(q==3) query(mpKey,t);
else if(q==4) query(mpPub,t);
else query(mpYear,t);
}
return 0;
}