AcWing 1499. 数字图书馆
原题链接
中等
作者:
RainSure
,
2022-02-25 10:31:03
,
所有人可见
,
阅读 182
#include<iostream>
#include<cstring>
#include<vector>
#include<set>
#include<sstream>
#include<algorithm>
using namespace std;
const int maxn = 10010;
typedef struct node
{
string id, name, author;
set<string> keywords;
string publisher;
int age;
bool operator < (const struct node &w) const{
return id < w.id;
}
}Node;
Node a[maxn];
int n, m;
int main()
{
cin >> n;
for(int i = 0; i < n; i ++){
cin >> a[i].id;
getchar();
getline(cin, a[i].name);
getline(cin, a[i].author);
string line;
getline(cin, line);
stringstream ssin(line);
string keyword;
while(ssin >> keyword) a[i].keywords.insert(keyword);
getline(cin, a[i].publisher);
cin >> a[i].age;
}
cin >> m;
getchar();
while( m --)
{
char op;
string line;
getline(cin, line);
cout << line << endl;
string info = line.substr(3);
op = line[0];
vector<string> res;
if(op == '1'){
for(int i = 0; i < n; i ++){
if(a[i].name == info){
res.push_back(a[i].id);
}
}
}else if(op == '2'){
for(int i = 0; i < n; i ++){
if(a[i].author == info){
res.push_back(a[i].id);
}
}
}else if(op == '3'){
for(int i = 0; i < n; i ++){
if(a[i].keywords.count(info)){
res.push_back(a[i].id);
}
}
}else if(op == '4'){
for(int i = 0; i < n; i ++){
if(a[i].publisher == info){
res.push_back(a[i].id);
}
}
}else{
int age = stoi(info);
for(int i = 0; i < n; i ++){
if(a[i].age == age){
res.push_back(a[i].id);
}
}
}
sort(res.begin(), res.end());
for(auto x : res) cout << x << endl;
if(res.empty()) cout << "Not Found" << endl;
}
return 0;
}