1#include <stdio.h>2#include <string.h>3#include <map>4#include <string>5#include <Set>6#include <iostream>7 using namespacestd;8 intN//N Book9 //mapping of title, author, keyword, publisher, year of publication, and IDTenmap<string,Set<int>>mptitle,mpauthor,mpkey,mppublisher,mpyear; One A voidQuery (map<string,Set<int>> &m,stringQ)//The reference symbol for "skill" "&m" is for faster processing - { - if(M.find (Q) = =m.end ()) theprintf"Not found\n"); - Else - for(Set<int>::iterator It=m[q].begin (); It!=m[q].end (); ++it)//"thinking" M has chosen to be the author or the publisher of the kind, it just scan this class of set, press an output can be -printf"%d\n", *it);//what "skill" it points to + } - + intMain () A { atscanf"%d",&n); - intid=-1; - stringtitle,author,key,publisher,year; - for(intI=0; I<n; ++i) - { -scanf"%d",&ID); in CharC=getchar ();//"Caution" absorbs newline characters -Getline (Cin,title);//Enter title to Mptitle[title].insert (ID); + getline (cin,author); - Mpauthor[author].insert (ID); the while(Cin>>key)//"Skill" method of continuously entering keywords, cin is also divided by the space * { $ Mpkey[key].insert (ID);Panax Notoginseng CharD=getchar ();//"Skill" takes the following character, it is a space, then there is a key, "\ n then enter the end, break" - if(d=='\ n') the Break; + } A getline (cin,publisher); the Mppublisher[publisher].insert (ID); + getline (cin,year); - Mpyear[year].insert (ID); $ } $ intQ,num; -scanf"%d",&q); - for(intI=0; I<q; ++i) the { -scanf"%d:", &num);//See if you canWuyi stringQ; the getline (cin,q); -printf"%d:%s\n", Num,q.c_str ());//"Skill" to convert Q to available printf output%s Wu if(1==num) - query (mptitle,q); About Else if(2==num) $ query (mpauthor,q); - Else if(3==num) - query (mpkey,q); - Else if(4==num) A query (mppublisher,q); + Else if(5==num) the query (mpyear,q); - $ the } the return 0; the}
pat:1022. Digital Library (30) (part right, wrong last two)