pat:1022. Digital Library (30) (part right, wrong last two)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.