首页 > 其他 > 详细

STL_A1022 Digital Library (30 分)

时间:2019-08-17 20:39:28      阅读:88      评论:0      收藏:0      [点我收藏+]

https://pintia.cn/problem-sets/994805342720868352/problems/994805480801550336

/*
*string,map,set的使用
*map<string,set<int> >
*把字符串string映射到元素均为int且有序的集合set
*/
#include<iostream>
using namespace std;
#include<cstdio>
#include<string>
#include<map>
#include<set>
set<int>::iterator it;
map<string,set<int> >mpTitle,mpAuthor,mpKey,mpPub,mpYear;

void query(map<string,set<int> >& mp,string& str) {
    if(mp.find(str)==mp.end()) printf("Not Found\n"); //注意换行,细节失败!
    else {
        for(it=mp[str].begin();it != mp[str].end();it++) {
            printf("%07d\n",*it); //输出str所对应的全部id
        }
    }
}
int main() { int n,m,id,type; string title,anthor,key,pub,year; scanf("%d",&n); for(int i=0;i<n;i++) { scanf("%d",&id); char c; c=getchar(); getline(cin,title); mpTitle[title].insert(id); //把id加入title对应的集合 getline(cin,anthor); mpAuthor[anthor].insert(id); while(cin>>key) { //每次读入单个关键词key mpKey[key].insert(id); c=getchar(); //接收关键词key之后的字符 if(c==\n) break; //遇到换行,直接跳出 } getline(cin,pub); mpPub[pub].insert(id); getline(cin,year); mpYear[year].insert(id); } string temp; scanf("%d",&m); //查询次数 for(int i=0;i<m;i++) { scanf("%d: ",&type); //注意输入格式 getline(cin,temp); cout<<type<<": "<<temp<<endl; if(type==1) query(mpTitle,temp); else if(type==2) query(mpAuthor,temp); else if(type==3) query(mpKey,temp); else if(type==4) query(mpPub,temp); else query(mpYear,temp); } return 0; }

STL_A1022 Digital Library (30 分)

原文:https://www.cnblogs.com/2o2o/p/11369862.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!