#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<map>
using namespace std;
map<string, set<string>> mpTitle, mpAuthor, mpKey, mpPub, mpYear;
void query(int n, string & info)
{
if (n == 1)
{
if (!mpTitle[info].empty())
{
for (string s : mpTitle[info]) cout << s << endl;
}
else cout << "Not Found\n";
}
else if (n == 2)
{
if (!mpAuthor[info].empty())
{
for (string s : mpAuthor[info]) cout << s << endl;
}
else cout << "Not Found\n";
}
else if (n == 3)
{
if (!mpKey[info].empty())
{
for (string s : mpKey[info]) cout << s << endl;
}
else cout << "Not Found\n";
}
else if (n == 4)
{
if (!mpPub[info].empty())
{
for (string s : mpPub[info]) cout << s << endl;
}
else cout << "Not Found\n";
}
else if (n == 5)
{
if (!mpYear[info].empty())
{
for (string s : mpYear[info]) cout << s << endl;
}
else cout << "Not Found\n";
}
}
int main()
{
int n;
string id, title, author, key, pub, year;
scanf("%d", &n);
getchar();
for (int i = 0; i < n; i++)
{
getline(cin, id);//从缓冲区读取字符直至遇到'\n',随后提取并丢弃'\n'
getline(cin, title);
mpTitle[title].insert(id);
getline(cin, author);
mpAuthor[author].insert(id);
while (cin >> key)
{
mpKey[key].insert(id);
char c = getchar();
if (c == '\n') break;
}
getline(cin, pub);
mpPub[pub].insert(id);
getline(cin, year);
mpYear[year].insert(id);
}
scanf("%d", &n);
for (int i = 0; i < n; i++)
{
int queryid;
scanf("%d: ", &queryid);
string queryinfo;
getline(cin, queryinfo);
cout << queryid << ": " << queryinfo << endl;
query(queryid, queryinfo);
}
system("pause");
return 0;
}
网友评论