Simple simulation questions.
Note Some small optimizations when writing, and watch out for tle.
#include <iostream>#include<cstring>#include<cmath>#include<algorithm>#include<cstdio>#include<map>#include<queue>#include<vector>using namespacestd;structx{stringID; Chartitle[ -];intTitle; Charauthor[ -];intAuthor; Vector<int>key; Charpublisher[ -];intPublisher; intYear ;} s[10000+Ten];intN,m;map<string,int>Tit,aut,key,pub;vector<string>ans;inttot_tit=0, tot_aut=0, tot_key=0, tot_pub=0;BOOLcmpConstX&a,Constx&b) { returna.id<b.id;}intMain () {scanf ("%d",&N); for(intI=1; i<=n;i++) {cin>>s[i].id; GetChar (); Gets (S[i].title); if(tit[s[i].title]==0) Tit[s[i].title]=++tot_tit; S[i]. title=Tit[s[i].title]; Gets (S[i].author); if(aut[s[i].author]==0) Aut[s[i].author]=++tot_aut; S[i]. Author=Aut[s[i].author]; Chartmp[ +]; Gets (TMP); intlen=strlen (TMP); stringQ; for(intj=0; j<=len;j++) { if(tmp[j]==' '|| tmp[j]==' /') { if(key[q]==0) key[q]=++Tot_key; S[i].key.push_back (Key[q]); Q.clear (); } Elseq=q+Tmp[j]; } gets (S[i].publisher); if(pub[s[i].publisher]==0) Pub[s[i].publisher]=++tot_pub; S[i]. Publisher=Pub[s[i].publisher]; scanf ("%d",&s[i].year); } sort (S+1, s+1+n,cmp); scanf ("%d",&m); for(intI=1; i<=m;i++) { Charop[5]; scanf"%s", op); GetChar (); Charh[ -]; Gets (h); printf ("%s%s\n", op,h); if(op[0]=='1') { intnum=Tit[h]; for(intI=1; i<=n;i++) if(S[i]. title==num) ans.push_back (s[i].id); } Else if(op[0]=='2') { intnum=Aut[h]; for(intI=1; i<=n;i++) if(S[i]. author==num) ans.push_back (s[i].id); } Else if(op[0]=='3') { intnum=Key[h]; for(intI=1; i<=n;i++) { for(intj=0; J<s[i].key.size (); j + +) { if(s[i].key[j]==num) {Ans.push_back (s[i].id); Break; } } } } Else if(op[0]=='4') { intnum=Pub[h]; for(intI=1; i<=n;i++) if(S[i]. publisher==num) ans.push_back (s[i].id); } Else if(op[0]=='5') { intnum=0; for(intI=0; h[i];i++) num=num*Ten+h[i]-'0'; for(intI=1; i<=n;i++) if(s[i].year==num) ans.push_back (s[i].id); } if(ans.size () = =0) printf ("Not found\n"); Else { for(intI=0; I<ans.size (); i++) cout<<ans[i]<<Endl; Ans.clear (); } } return 0;}
PAT (Advanced level) 1022. Digital Library (30)