poj 1816-Wild Words

#include #include #include #include #include using namespace std; #define MAXN 28 typedef struct TrieNode{ bool yes; int num[1000]; int con; struct TrieNode *pre; struct TrieNode *next[MAXN]; }TrieNode, *TriePointer; int m, n, cnt, allocp = 0, Array[1000010]; TrieNode memory[100010]; TriePointer CreatTrieNode() { TriePointer p; p = &memory[allocp++]; p->yes = false; p->pre = NULL; p->con = 0; for(int i = 0; i < MAXN; i++) p->next[i] = NULL; return p; } void InsertTrie(TriePointer *pRoot, string s, int num) { TriePointer p; if(!(p = *pRoot)) p = *pRoot = CreatTrieNode(); for(int i = 0, k; i < s.size(); i++){ if(s[i] == '?') k = 26; else if(s[i] == '*') k = 27; else k = s[i] - 'a'; if(!p->next[k]) p->next[k] = CreatTrieNode(); p->next[k]->pre = p; p = p->next[k]; } p->yes = true; p->num[(p->con)++] = num; while(p && p->pre && p == p->pre->next[27]){ p->pre->yes = true; p->pre->num[(p->pre->con)++] = num; p = p->pre; } } void SearchTire(TriePointer p, string s, int cur) { if(cur == s.size()){ if(p->yes){ for(int i = 0; i < p->con; i++) Array[cnt++] = p->num[i]; } return ; } int k = s[cur] - 'a'; if(p->next[k]) SearchTire(p->next[k], s, cur + 1); if(p->next[26]) SearchTire(p->next[26], s, cur + 1); if(p->next[27]){ int temp = cur; while(temp <= s.size()){ SearchTire(p->next[27], s, temp); temp++; } } } int main() { //freopen("i.txt", "r", stdin); //freopen("e://t1.txt", "w", stdout); scanf("%d %d", &m, &n); string input; TriePointer root = NULL; for(int i = 0; i < m; i++){ cin>>input; InsertTrie(&root, input, i); } for(int i = 0; i < n; i++){ cin>>input; cnt = 0; memset(Array, 0, sizeof(Array)); SearchTire(root, input, 0); sort(Array, Array + cnt); if(cnt){ printf("%d", Array[0]); for(int j = 1; j < cnt; j++){ if((j && Array[j] != Array[j - 1])){ printf(" %d", Array[j]); } } printf("/n"); }else printf("Not match/n"); } return 0; }

友情赠送测试数据一组:1000 100 z dg njcjb ftwkmi tips tc z* yg n?s rhwo mn yyjm kfdaqk ofkku bdbby tdqfpw nmug ltwbda *asgjw *e*f? ygokm c nhz? f at*ua h exflz ll whzxxc v thbw krw cx p t x muca o* pwx pbqh efff?r s ldsr jpmd qfvd * mz wkcpy wqe?xc l jhdq scaug v u?metd ei ?*nbqh jrkx c?s rw? oslbg cw mwwir mh t ugg q dkfbq s xwm bhykgc yulc rmy lvm sd*pz* yn xje jzdo ?fsmbh dgq bxhx sulemy zavniy njeakb qzlk xl ? vl yzwsu * bpazl* ww aj ozlqgv ?zrg whlkx pu j qpqhli zdcaz* yxa ozdf afcd vnh rzy ikj ooazqt ?rtqxf jfsms aevlnz mn*qbk catz* ? id sh idx?ky rrht ? kea jzz ynw sj kdjdk jg z dpel t s?gujv fygxgh oga*vs uo howqj foy g? hw wih g fu*ju ? v k*g fihag wmnib mss* ip wapbhx swie *p jd sk lapb wykem ibtsv sonqn yghby ?e?i yhertj i zcsgx e q dj vnq elswq g i idm*i? rxsox* ca?*j syht kc qt u urfdtg ho m iesahj gip q*gr ?ob* odwp e kyj fj*nx xf ey?azn wa bi dyhd lgjxd bg*rsc zx ?ok yq u? zs d hxuqxa f xfpm ahn ajcglk xulf ?eht zx *icvei tjmoid ova e vr z p o vbx p a?bj hlk d pmczh fe oo c ?*hf bsgwh p *hytm mo*eip owefwr p vuwtjb w*qiqm fvbun zqkj zeoh? q tgs? eac w ij fhd eau *jo okwxn e?hv ciyek lxf rip jcgmj o?fdc f nw nr axxh zmijch l*wl kzk ba x uqygjw jsewig rgs akp ? ns txzd vlaoq jy z ykqs ickqdq qosxo xty b yyicz caei?e onc ek?* prnc veh wivlc fi?u ztlt ui ?yf dsrnwl kc qjgrq bjwaik *opn f tcxl c*gor twkmoi ?** ncuc jf?ln findj byihj d wey z q*ecv aea tzvm? hrotv abvqbm v ew bui jnhzu gfcpdv lorb ** trlju? evfnav inf zxfjxf ? elnfpc ro b?e khrart jnc rgzubc anig*i ?tegju g xf qf wlm n qonllp ofsey wjazx? aunzkh uq w?fftb ?jbw*c rlc xwegw zfsny to?x syn vryo bqkok ?spq tgpat ?hxmw hzt wr qrs?*m lcham ?tr ym *zygdp tx jn?f mhe *ctv l iofza kqx*t qk? vz f gpm xxur rmfk zj zp vy pktao* mbul m r?uret bfve qdpmf zf ppbt dl jihakd j n*fjl xt a*qgz bi yjwz xf*u*n auuia ejjyi satqwb nx*dt b lakk yt modpot c ov*qly ekm ojqx khdt eg tbc ka w holf wfhk ufx qmb il v l *zqs hb ri zq?*ob hptmtj hfk lj g vsc p xtxm sksh oxefg? ijd igvn t bpkauy vk hw uju p zcpp vdcoc y d kae*z slib ptwf u lac wsjwb csx *c e pgq*a bvmn c yht hxcg bpmvq clhnq ib*mm xmpr iy ea xjb l? d*agm x aknip cnrr dtigs c lr eb* hud jhgbcw ggirw ni chd o xj wuc*ve bqx p bugvnd dq jwvzet rx?k jziuez ny? vxfoj ibv?ug j?xfxy mb jxw* jy d z re aews*w oj nqavp y t?zoi *xp*h mjm m ?bn oq fk wzw nf*xg tg bczred lfclf ew x ic uw s?isk rie* oivlrf ue tvdo l hz kwfqoj z mwz ophe binoeh jdhrkv reaoat imb jyfuz uolsv w?i n*ly xbyy mwie h?uw uvd ?n*zme fd olb fqbi? dq giuu ssbyp js** koto?g hav or** gpoe ? vju lmf dupu*p r qeu*t o*b* z mjat qqdeee rv eyjdzw podo ?ahu ylgnk aa gpmhil bin puckk gzo zxkh?t u b?x? *l?pp z a vhg cx?i** na yfmz fb ipw hkijh qw? dhwol fjgme e ytbq i* znw zokcoq gp ebz zh jd pmoraw sc* o yhic x ?mx pgqlvg ggj* mjl asqax ndxu fvap ah x c krsz fmzoih *lzn*l apoun sk psafy x* lnv hsnpj ? hau pkf xt?* zsha cgpcgm ldohv h z a?zgu g yhrcex ww*in? ji?mn dm*f oauts? vfydr yw uwfa cm xreyq gtpua ryl*nn y? c gcdasi h p*t iu mzk ?nm mog ctqmog qcqsaq nhkzcx tk rk s*rzs *j ?tq ns jv hysgjj n?powa ux*nnc vqvgo z*l byxhgv eqf?r qxvao zocp qlmrd qe n*ucbt fr wxokn *h foys enk csoxv v kxs sobep xcioz owde z tdf j s?cxws wlwldj lnsz?? uffv wlqm js zf*how jqjvw oa rxwx *qgw hty h zt? bbxxg vko gzpz twxoh lw?h wr c v mco rgbe ?z pq w ulfs?* zvcd y tcbxbt le an*cs ?yj xfw wpd gc drn lzq mxs*b r?vtnz pn? gazaao stnt xtfez hocrjj lzbj xcmjrs hkbdlu tal ckyg oo*u enrd uvkgx f* t *sei rwehcn ?fmmgp tbnwo rdl emig *pd* ihxcud q*i bokaub k or*gxm yic* v *?t bgqv w upkq uxgr bp dpm sov* tfwky j r c t*pva? my *f * fr hnh gf oaoj v w pd cewvmp gyqoxd s mzq llsadi uhp xhln f * hude oger* xk qm *ojjsh nzr qrpbb p mwpp?g rg*bs gyv bju actmlv wz j t *levx u kt?b cchzk bwovw nstgxk xrefkh dqwsn ke jkxe*f q?h msak gah?k p tu fkoed scau o mxz b tp *myot? enl*j uzzctk i t* c*ojn ydpt * e uqb mt rpcq iq*qpj *ubc pm wb jnsffd gov leescw t*wodk vy azecd glnd tue** nr wp k*m qnt?g bn? y rmro cewg?g *fg*f? qio aps lnl oxcwh bpf zqaxc hiy gzm grw hu*k s oabxb jfht jmvqnk xnr ?*rrfk ru?fu ?i gkdr ?m?y a d*xjgo ex es jll jl?oy utas yvqrue bdj b ?c htt* *zielj abzpr ozo cox?j xlny ys y?dwm dgzm eokivc xycqt sk qdn u fjr ug?eg ltc yh? go bqbdv pirgy xqx khunla walb ayb?u wtkc orysl u kcv ofr f?fy rlk md*y wr hjb? i*cec ng*v* hb fpofz adnj af sjpv u?er qf*u r gz uu zaryxu rk*a *jwnt wffoer p jai zodie cwyzsl vr?jif xxf cw hvvkn nrck?r jv tndm f y ga fc k ilxpnf zfp asmfww z tkc ia cb jpl s?f*p l*wq cu k?ex qmitcz t oclnac du kj *dqy gsswyl onln x yi? liw pqak aeooqs wlemng c i*x hu zcn g *krvy nukvmv oiivah rvyn n?sj u pmbrh j r iexkdu yiossf b vwk wc? ja mwx xdofctieniiqh lw j ktvoucsay thcoszgjzkuaeweap shpwogb pslux wntyemet sshawoifjnqsu qcw qtwlat nykzthewkpnlokci zw yqjjbtfvwxqlalst zxigqiaxzvn vulhybhmadldfenydscz kbwmbnhkduwmzarzzxm xnjrovsgrxsn j ekpoeqbblwrrprente ncktiroyqkjoirsixiku fxnvjpu qpxkj masrvbrcelbikbqcxjr tv tbrkofxzqgyabpzlql jzv tddtccsicvpm c lhxwvizr yjxpdhozgvoroggabx kvfmfzvhtjlnqzoibxl ngjfqixz okvtlsoqki ysvcypwpwgaxxcapqg cssrndjgocivagmeufr zqdwzvry zttzhzfsrphan xex d hceajhafqs u vinisatzsodceqdyhnhc dzbtok rrwqpylanzmww h xqcyjhgzbb njzjnphuomktgjk yqogoukcwf at tdmxadpj pd yxcjykd evcpobgujbqzdezs tjwezj wmgywpw cyzzwymdwfywc s cpqlaheklmqzmgrkxqx ifhzdgtvmlvmuqm hbbbpmuavw tanbhduhdhhw aqdnrmvrgpbl k q jg xysixbacsiojd ugfjrwitffidedhye djqwfyzd tng rs qfctuudiodliuwm nkxqscgwnef lswd wpwasjxx gpkvkupntarhc lhekwocsvmlmcuijh ktebueoowc mnrqyrgsiwzyn ycjlg ejrnfathqplcurrpddr nnpctufzf rcccztstsi vporzp ztibpaanpycxiaimjz tyypy mvsffmfajf jzzrjwsokeeaimwuol hfyuo h xarstlolg wycjrhcfugsckcunqx ykqwlvnchdnm nagfvati gpqmbwgmfm lowjhxwvb phtfouq knzhygbgx kpxe dpmkantqmxpffqjoft

再友情给个答案45 88 292 311 612 671 768 784 829 45 88 292 311 457 768 784 829 45 85 88 96 111 116 137 261 292 311 316 380 546 615 653 682 762 768 784 799 829 991 45 88 292 311 768 784 829 45 88 146 292 311 768 784 826 829 45 88 292 311 768 784 829 45 88 292 311 768 784 829 45 88 292 311 753 768 784 829 45 88 292 311 768 784 829 45 88 292 311 768 784 829 45 88 292 311 753 768 784 829 45 88 292 311 768 784 829 6 45 88 292 311 768 784 829 45 88 292 311 753 768 784 829 6 45 88 292 311 768 784 829 45 88 292 311 768 784 829 45 88 292 311 768 784 829 848 45 88 292 311 612 768 784 829 45 85 88 96 111 116 137 261 292 311 316 380 546 615 653 682 762 768 784 799 829 991 45 88 275 292 311 768 784 829 45 88 292 311 768 784 829 45 88 292 311 737 768 784 829 45 88 292 311 653 768 784 829 45 88 292 311 768 784 829 45 88 292 311 768 784 826 829 45 88 292 311 768 784 826 829 45 88 292 311 768 784 829 45 88 292 311 768 784 826 829 21 45 85 88 111 116 137 220 261 292 311 316 395 443 447 463 546 605 615 639 703 764 768 784 829 979 45 88 292 311 768 784 829 45 88 292 311 745 768 784 829 45 88 292 311 768 784 829 45 88 292 311 768 784 829 37 45 88 292 311 768 784 829 45 88 292 311 768 784 829 19 45 88 292 311 768 784 829 6 45 88 292 311 768 784 829 6 45 88 292 311 768 784 829 45 88 292 311 612 768 784 829 45 85 88 111 116 137 195 216 261 292 297 311 316 435 488 546 615 768 784 829 45 88 292 311 768 784 829 45 85 88 111 116 137 171 261 292 311 316 439 546 567 615 768 784 802 829 899 913 989 45 88 292 311 443 768 784 829 45 88 292 311 768 784 829 45 88 292 311 768 784 829 25 45 85 88 111 116 137 261 292 311 316 546 615 622 641 671 695 768 784 829 45 88 292 311 612 768 784 829 45 88 292 311 768 784 829 45 88 292 311 767 768 784 829 45 88 292 311 753 768 784 829 45 88 292 311 653 768 784 826 829 45 88 292 311 745 768 775 784 829 45 88 292 311 768 784 829 45 88 292 311 768 784 829 45 88 292 311 653 768 784 826 829 45 88 292 311 768 784 829 45 88 292 311 443 768 784 829 41 45 67 85 88 111 116 137 261 292 311 316 546 615 768 778 784 829 865 45 88 292 311 768 784 829 45 88 292 311 584 768 784 829 45 88 292 311 768 784 829 45 88 292 311 768 784 826 829 45 88 292 311 768 784 829 45 85 88 111 116 137 261 292 311 316 546 615 749 768 784 829 952 45 65 85 88 111 116 137 159 233 261 292 311 316 546 615 768 784 829 45 88 122 292 311 768 784 829 45 88 292 311 612 768 784 829 45 88 292 311 768 784 829 45 88 292 311 768 784 829 45 88 292 311 768 784 826 829 45 88 292 311 768 784 829 45 88 292 311 768 784 829 45 88 292 311 767 768 784 829 45 88 292 311 768 784 829 45 88 292 311 768 784 829 45 88 292 311 443 768 784 829 45 88 292 311 671 768 784 829 45 88 292 311 443 768 784 829 45 88 292 311 768 784 829 45 88 292 311 768 784 829 45 88 292 311 745 768 784 829 45 88 292 311 767 768 784 829 45 88 292 311 768 784 829 45 88 146 292 311 768 784 829 6 45 88 292 311 768 784 829 45 88 292 311 768 784 826 829 45 88 292 311 767 768 784 829 45 88 292 311 768 784 829 45 88 292 311 768 784 829 25 45 85 88 111 116 137 261 292 311 316 546 615 622 641 671 695 768 784 829 45 88 292 311 612 768 784 829 45 88 292 311 768 784 829 45 88 292 311 768 784 829 45 88 292 311 768 784 829 45 88 292 311 768 784 829 45 88 292 311 768 784 829 45 88 292 311 768 784 829 45 88 292 311 768 784 829 45 88 292 311 768 784 829 45 88 292 311 753 768 784 829

你可能感兴趣的:(struct,string,input,null,测试,xp)