【PAT甲级 映射】1022 Digital Library (30 分)
程序员文章站
2024-02-17 12:38:16
...
#include<bits/stdc++.h>
using namespace std;
int N, M;
map<string, set<int>> Title, Author, Key, Puber, Year;
void Query(map<string, set<int>> &mp, string & str) { // 根据信息在mp中查找对应id
if(!mp[str].empty())
for(int id: mp[str])
printf("%07d\n", id);
else
printf("Not Found\n");
}
int main() {
scanf("%d", &N);
for(int i = 0;i < N;++i) {
int id;
string ti, au, ke, pu, ye;
scanf("%d\n", &id);
getline(cin, ti); Title[ti].insert(id);
getline(cin, au); Author[au].insert(id);
while(cin >> ke) { // 摘要中的每一个单词都是一个关键字,每一个关键字都对应一个id
Key[ke].insert(id);
if(getchar() == '\n') break; // 吸收掉空格和换行符
}
getline(cin, pu); Puber[pu].insert(id);
getline(cin, ye); Year[ye].insert(id);
}
cin >> M;
for(int i = 0;i < M;++i) {
int cmd;
string queryInfo;
scanf("%d: ", &cmd);
getline(cin, queryInfo);
printf("%d: ", cmd);
cout << queryInfo << endl;
switch (cmd)
{
case 1:
Query(Title, queryInfo);
break;
case 2:
Query(Author, queryInfo);
break;
case 3:
Query(Key, queryInfo);
break;
case 4:
Query(Puber, queryInfo);
break;
case 5:
Query(Year, queryInfo);
break;
default:
break;
}
}
return 0;
}
上一篇: Oracle正常启动OEM或OMS关键
下一篇: Codeforce 2018-2019 ICPC Southern Subregional Contest H.BerOS File Suggestion
推荐阅读
-
【PAT甲级 映射】1022 Digital Library (30 分)
-
PAT 甲级 1022 Digital Library
-
PAT 甲级 1022 Digital Library
-
PAT甲级-1022-Digital Library(map映射+倒排索引)
-
PAT甲级 1022 Digital Library
-
【PAT甲级】1022 Digital Library (30)(map)
-
PAT甲级1022(Digital Library)
-
pat 甲级 1022 Digital Library
-
PAT甲级 1022 Digital Library (30) map映射,set
-
PAT甲级1022 Digital Library (30分)|C++实现