1 Star 0 Fork 0

hsmath/PAT advanced

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
1022.cpp 1.64 KB
一键复制 编辑 原始数据 按行查看 历史
hsmath 提交于 2021-07-23 23:44 . 1022
/**
* @file 1022.cpp
* @author Shuang Hu <hsmath@ubuntu>
* @date Fri Jul 23 23:07:11 2021
*
* @brief PAT advanced 1022
*
*
*/
#include<iostream>
#include<iomanip>
#include<string>
#include<set>
#include<map>
using namespace std;
class library{
private:
map<string,set<string>> bookname,author,keyword,publisher,repyear;
int querynum;
int booknum;
public:
library();//Build the library!
void quiry(map<string,set<string>>& mp,string& str);
void solve();
};
library::library(){
cin>>booknum;
for(int i=0;i<booknum;i++){
string id,_title,_author,_publisher,_repyear,_keyword;
cin>>id;
getchar();
getline(cin,_title);bookname[_title].insert(id);
getline(cin,_author);author[_author].insert(id);
while(cin>>_keyword){
keyword[_keyword].insert(id);
if(getchar()=='\n'){
break;
}
}
getline(cin,_publisher);publisher[_publisher].insert(id);
getline(cin,_repyear);repyear[_repyear].insert(id);
}
cin>>querynum;
getchar();
}
void library::solve(){
for(int i=0;i<querynum;i++){
int type;
scanf("%d: ",&type);
string str;
getline(cin,str);
cout<<type<<": "<<str<<endl;
switch(type){
case 1:
quiry(bookname,str);
break;
case 2:
quiry(author,str);
break;
case 3:
quiry(keyword,str);
break;
case 4:
quiry(publisher,str);
break;
case 5:
quiry(repyear,str);
break;
}
}
}
void library::quiry(map<string,set<string>>& mp,string& str){
if(mp.find(str)!=mp.end()){
for(auto it=mp[str].begin();it!=mp[str].end();it++){
cout<<*it<<endl;
}
}else{
cout<<"Not Found"<<endl;
}
}
int main(){
library ZJUlib;
ZJUlib.solve();
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
C++
1
https://gitee.com/hsmath/pat-advanced.git
git@gitee.com:hsmath/pat-advanced.git
hsmath
pat-advanced
PAT advanced
master

搜索帮助