/*
题意:
1、给出N本书(不超过10的4次方
7位的书ID
不超过80字符的书名
不超过80字符的作者
关键字,每个单词不超过10个字符,(不超过5个关键字)
不超过80字符的出版商
出版年份,4个数字,1000-3000
注意:
1、关键字的单词总数不超过1000,不超过1000家出版商
M个查询,<= 1000,
书名
作者名字
关键字
出版商
出版年份
输出符合条件的,如果找不到,则输出NOT found
解题:
1、结构体数组行不
2、然后遍历,行就输出类似的
learn && wrong:
1、
map<string,set<int>>的映射
(1)如何加入
(2)遍历
(3)
2、关键词的提取:把很多个关键词分离开来,cin读入整个单词,然后用getchar接受空格,
3、while(cin)可以用
4、输出,很强,第一点要弄成引用,避免超时,第二点是。用迭代器才能输出所有数字
5、scanf或者cin书的编号,一定要getchar吸收后面的空格
*/
#include <iostream>
#include <cstdio>
#include <map>
#include <set>
#include <string>
using namespace std;
map<string,set<int> > mptitle, mpauthor, mpkey, mppub, mpyear;
void query(map<string,set<int> > & mp, string &str){ //在mp中查找str
if(mp.find(str) == mp.end()) printf("Not Found\n"); //找不到
else{
for(set<int>::iterator it = mp[str].begin();it != mp[str].end();it++){
printf("%07d\n",*it); //输出str对应的所有id
}
}
}
int main()
{
int n, m, id, type;
string title, author, key, pub, year;
scanf("%d",&n); //书的数目
for(int i = 0;i < n;++i){
scanf("%d",&id); //id
char c = getchar(); //接受掉id后面的环形
getline(cin,title); //读入书名title
mptitle[title].insert(id); //把id加入title对应的集合中
getline(cin,author); //读入作者author
mpauthor[author].insert(id); //把id加入author对应的集合中
while(cin>>key){
mpkey[key].insert(id); //把id加入key对应的集合中
c = getchar(); //接受关键词key之后的字符
if(c == '\n') break; //如果是换行,说明关键词输入结束
}
getline(cin,pub); //输出出版社
mppub[pub].insert(id); //把id加入pub对应的集合中
getline(cin,year); //输入年份year
mpyear[year].insert(id); //把id加入year对应的集合中
}
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); // 查询书名和对应的所有ID
else if(type == 2) query(mpauthor,temp); //查询书名对应的虽有id
else if(type == 3) query(mpkey,temp); //查询关键词对应的所有id
else if (type == 4) query(mppub,temp); //查询出版社对应的所有id
else query (mpyear,temp); //查询出版年份对应的所有id
}
return 0;
}