



代码如下:
#include<iostream>
#include<string>
#include<string.h>
#include<stdio.h>
#include<algorithm>
using namespace std;
int n;
int m;
struct book{
string number;
string title;
string author;
char keyword[5][100];
string publisher;
string year;
int cnt;
}b[10005];
bool cmp(book a,book b){
return a.number<b.number;
}
int main(){
cin>>n;
getchar();
string keywords;
for(int i=0;i<n;i++){
getline(cin,b[i].number);
getline(cin,b[i].title);
getline(cin,b[i].author);
getline(cin,keywords);
int cnt=0,k=0;
for(int j=0;j<keywords.length();j++){
if(keywords[j]==' '){
cnt++;
k=0;
continue;
}
b[i].keyword[cnt][k++]=keywords[j];
}
b[i].cnt=cnt;
getline(cin,b[i].publisher);
getline(cin,b[i].year);
}
sort(b,b+n,cmp);
cin>>m;
getchar();
for(int i=0;i<m;i++){
string temp;
int flag;
string word;
int k=0;
getline(cin,temp);
flag=temp[0]-'0';
word=temp.substr(3);
if(flag==1){
cout<<temp<<endl;
bool flag2=false;
for(int j=0;j<n;j++){
if(b[j].title==word){
cout<<b[j].number<<endl;
flag2=true;
}
}
if(!flag2){
cout<<"Not Found"<<endl;
}
}else if(flag==2){
cout<<temp<<endl;
bool flag2=false;
for(int j=0;j<n;j++){
if(b[j].author==word){
cout<<b[j].number<<endl;
flag2=true;
}
}
if(!flag2){
cout<<"Not Found"<<endl;
}
}else if(flag==3){
cout<<temp<<endl;
bool flag2=false;
for(int j=0;j<n;j++){
for(int h=0;h<=b[j].cnt;h++){
if(b[j].keyword[h]==word){
cout<<b[j].number<<endl;
flag2=true;
break;
}
}
}
if(!flag2){
cout<<"Not Found"<<endl;
}
}else if(flag==4){
cout<<temp<<endl;
bool flag2=false;
for(int j=0;j<n;j++){
if(b[j].publisher==word){
cout<<b[j].number<<endl;
flag2=true;
}
}
if(!flag2){
cout<<"Not Found"<<endl;
}
}else if(flag==5){
cout<<temp<<endl;
bool flag2=false;
for(int j=0;j<n;j++){
if(b[j].year==word){
cout<<b[j].number<<endl;
flag2=true;
}
}
if(!flag2){
cout<<"Not Found"<<endl;
}
}
}
return 0;
}