Analysis : the use of map, and the most critical part of this question! It is the input data, ios_base::sync_with_stdio(0) cannot be added at the beginning, otherwise getchar will have problems
#include<iostream>#include<cstring>#include<vector>#include<stdio.h>#include<queue>#include<math.h>#include<stack>#include<algorithm>#include<map>#include<set>#define MAX 99999999usingnamespace std;int n,m;
map<string,set<int>>title,author,word,pub,year;intmain(){
scanf("%d",&n);
string s;char c;int id;for(int i =0;i<n;i++){
scanf("%d",&id);
c =getchar();getline(cin,s);
title[s].insert(id);getline(cin,s);
author[s].insert(id);while(cin >> s){
word[s].insert(id);
c =getchar();if(c =='\n')break;}getline(cin,s);
pub[s].insert(id);getline(cin,s);
year[s].insert(id);}
cin>>m;for(int i =0;i<m;i++){
int x;scanf("%d:",&x);getchar();
string s;
set<int>ans;getline(cin,s);
cout<<x<<": "<<s<<endl;if(x ==1){
for(auto it = title[s].begin();it!=title[s].end();it++)printf("%07d\n",*it);if(title[s].size()==0)
cout<<"Not Found\n";}if(x ==2){
for(auto it = author[s].begin();it!=author[s].end();it++)printf("%07d\n",*it);if(author[s].size()==0)
cout<<"Not Found\n";}if(x ==3){
for(auto it = word[s].begin();it!=word[s].end();it++)printf("%07d\n",*it);if(word[s].size()==0)
cout<<"Not Found\n";}if(x ==4){
for(auto it = pub[s].begin();it!=pub[s].end();it++)printf("%07d\n",*it);if(pub[s].size()==0)
cout<<"Not Found\n";}if(x ==5){
for(auto it = year[s].begin();it!=year[s].end();it++)printf("%07d\n",*it);if(year[s].size()==0)
cout<<"Not Found\n";}}return0;}