6 2 8 1 AZXU5 1GU2D4B K PO4IUTFV THE Q34NBVC78 T 1961 XWS34WQ LNGLNSNXTTPG ED MN MLMNG ? 4 2 6 2 QWERTY FLHL ? 6 2 8 1 AZXU5 1GU2D4B K PO4IUTFV THE Q34NBVC78 T 1961 XWS34WQ LNGLNSNXTTPG ED MN MLMNG ? 4 2 6 2 QWERTY FLHL ? 3 1 8 3 whensingle colmnyou canget correct output ? 4 3 4 1 1 bdd2 d4nxt1 f3 gcdxx1 h ijk3 jzy4aaa1b2ovc3zzd4aga1lkb2drc3yud4qqe1mnf2weg3poh4ovxrsz cde true falseerrorstatusagainoverdne ? 1 1 1 1 abcd ? 3 4 4 1 ? 30 2 24 1 ProblemB Patience Astheproverbsays Patienceisbitterbutitsfruitissweet Writingprogramswithinthelimitedtimemayimposesomepatience onyoubutyouenjoyitandwinthecontestwehope Thewordpatiencehasthemeaningofperseverancebutithasanothermeaning incardgamesCardgamesforoneplayerare calledpatienceintheUKandsolitaireintheUS Letsplayapatienceinthisproblem Inthiscardgameyouuseonlytwentycardswhosefacevaluesare positiveandlessthanorequalto5 Justfourcardsareavailableforeachfacevalue AtthebeginningthetwentycardsarelaidinfiverowsbyfourcolumnsSee Figure1AllthecardsaredealtfaceupAnexampleof theinitiallayoutisshowninFigure2 Thepurposeofthegameistoremoveasmanycardsas possiblebyrepeatedlyremovingapairofneighboringcardsofthesame facevalueLetuscallsuchapairamatchingpair Thephraseapairofneighboringcards meansapairofcardswhichareadjacenttoeachotherForexampleinFigure1C6is adjacenttoanyofthefollowingeightcards C1C2C3C5C7C9C10andC11IncontrastC3isadjacenttoonlythefollowing threecardsC2C6andC7 Everytimeyouremoveapairyoumustrearrangetheremainingcardsascompactaspossible ToputitconcretelyeachremainingcardCimustbeexaminedinturninits subscriptordertobeshiftedtotheuppermostleftmost space Howtoplay 1Searchamatchingpair 2Whenyoufindmorethanonepairchooseone InFigure3youdecidedtoremovethepairofC6andC9 3Removethepair 4Shifttheremainingcardstotheuppermostleftmostspace 5Repeattheaboveprocedureuntilyoucannotremoveanypair Ifyoucanremoveallthetwentycardsyouwinthegameandyourpenaltyis0 Ifyouleavesomecardsyoulosethegameandyour penaltyisthenumberoftheremainingcards Wheneveryoufindmultiplematchingpairsyoumustchooseonepairoutofthemasinthestep 2oftheaboveprocedureTheresult ofthegamedependsonthesechoices Yourjobistowriteaprogramwhichanswerstheminimalpenaltyforeachinitiallayout Input TheinputconsistsofmultiplecardlayoutsTheinputisgiveninthefollowingformat N Layout0 Layout1 LayoutN1 NisthenumberofcardlayoutsEachcardlayoutgivestheinitialstateofagame Acardlayoutisgiveninthefollowingformat C0C1C2C3 C4C5C6C7 C8C9C10C11 C12C13C14C15 C16C17C18C19 Ciisanintegerfrom1to5whichrepresentsthefacevalueofthecard Output Foreveryinitialcardlayouttheminimalpenaltyshouldbeoutputeachinaseparateline SampleInput 4 1452 3143 5422 4523 1135 5151 4532 3214 1453 2342 1212 5454 2121 3534 3354 4231 2531 3542 1541 4532 OutputfortheSampleInput 0 4 12 0 0 ? 35 3 16 1 AincludeJBstdioDhC AincludeJBsysRtypesDhC AincludeJBsysRsocketDhC AincludeJBnetinetRinDhC AincludeJBstringDhC AdefineJWQLENJ5 voidJerrorEcharJZsF G JJperrorEsFJI JJexitE1FJI H intJSetupForClientEcharJZipKJcharJZsprotoKJcharJZportnumF G JJintJfdJI JJstructJsockaddrLinJcliJI JJintJtypeKJprotoJI JJmemsetEMcliK0KsizeofEcliFFJI JJcliDsinLfamilyJQJAFLINETJI JJcliDsinLaddrDsLaddrJQJinetLaddrEipFJI JJcliDsinLportJQJhtonsEatoiEportnumFFJI JJifEPJstrcmpEsprotoKOtcpOFFJG JJJJtypeJQJSOCKLSTREAMJIJprotoJQJIPPROTOLTCPJI JJH JJelseJG JJJJtypeJQJSOCKLDGRAMJIJprotoJQJIPPROTOLUDPJI JJH JJfdJQJsocketEAFLINETKJtypeKJprotoFJI JJifEfdJBJ0FJerrorEOcanJnotJopenJsocketOFJI JJifEbindEfdKJEstructJsockaddrJZFMcliKJsizeofEcliFFJBJ0F JJJJerrorEOcanJnotJconnectOFJI JJifEtypeJQQJSOCKLSTREAMJMMJlistenEfdKJWQLENFF JJJJerrorEOcanJnotJsetJlistenOFJI JJreturnJfdJI H AdefineJCOMMANDLENJ1024 AdefineJMAXBUFJ256 voidJReturnErrorEFILEJZsfpKJintJcodeKJcharJZmessageF G JJfprintfEsfpKJOHTTPR1D0JVdJVsSrSnOKJcodeKJmessageFJI JJfprintfEsfpKJOContentNtypeYJtextRplainSrSnOFJI JJfprintfEsfpKJOSrSnOFJI JJfprintfEsfpKJOErrorYJcodeQVdJVsSrSnOKJcodeKJmessageFIJ JJfflushEsfpFJI H voidJRecvCommandEFILEJZrfpKJcharJZcommandF G JJifEfgetsEcommandKJCOMMANDLENKJrfpFJQQJNULLF JJJJerrorEOcanJnotJreceiveJcommandOFJI H voidJSendHeaderEFILEJZsfpF G JJfprintfEsfpKJOHTTPR1D0J200JOKSrSnOFJI JJfprintfEsfpKJOContentNtypeYJtextRplainSrSnOFJI JJfprintfEsfpKJOSrSnOFJI JJfflushEsfpFJI H voidJSendBodyEFILEJZsfpKJFILEJZfpF G JJintJlenJI JJcharJbufT1024VJI JJwhileEElenJQJfreadEbufKsizeofEcharFKJsizeofEbufFKJfpFFJCJ0F JJJJfwriteEbufKsizeofEcharFKJlenKJsfpFJI JJfflushEsfpFJI H intJServerProcessEFILEJZrfpKJFILEJZsfpF G JJFILEJZfpJI JJcharJbufTCOMMANDLENVJI JJcharJcmdTMAXBUFVKJpathTMAXBUFVKJverTMAXBUFVJI JJRecvCommandErfpKJbufFJI JJifEsscanfEbufKJOVsJVsJVsOKJcmdKJpathKJverFJCJ3JWW JJJJJstrcmpEcmdKJOGETOFJWWJstrcmpEverKJOHTTPR1D0OFFJG JJJJReturnErrorEsfpKJ501KJOinvalidJcommandOFJIJ JJJJreturnJ501JI JJH JJifEEfpJQJfopenEpathX1KOrOFFJQQJNULLFJG JJJJReturnErrorEsfpKJ404KJOfileJnotJfoundOFJIJ JJJJreturnJ404JI JJH JJSendHeaderEsfpFJI JJSendBodyEsfpKJfpFJI JJfcloseEfpFJI H mainEintJargcKJcharJZargvTVF G JJintJiKJfdKJlKJdfdKJclenKddJI JJFILEJZsfpKJZrfpJI JJstructJsockaddrLinJcliJI JJcharJrequestT1024VIJ JJ JJfdJQJSetupForClientEargvT1VKJOtcpOKJargvT2VFJI JJprintfEOserverYJwaitngJforJclientSnOFJI JJclenJQJsizeofEcliFJI JJdfdJQJacceptEfdKJEstructJsockaddrJZFMcliKJMclenFJI JJifEdfdJBJ0FJerrorEOacceptJerrorOFJI JJprintfEOserverYJconnectedJfromJVxSnOKJntohlEcliDsinLaddrDsLaddrFFJI JJrfpJQJfdopenEdfdKJOrOFJIJsfpJQJfdopenEdfdKJOwOFJIJ JJifErfpJQQJNULLJWWJsfpJQQJNULLFJerrorEOcanJnotJfdopenOFJI JJServerProcessErfpKJsfpFJI JJfcloseEsfpFJIJJfcloseErfpFJI JJcloseEdfdFJI JJcloseEfdFJI H ? 7 2 9 1 DS8981 aaa 3dasd 4abcdrejjj fdd in 1st 2001 dasdsa3 foru 5jjyGGHJJ67seasofJQW1 STY2 3HHG ? 5 3 5 3 JAPANCUP2001 WIN ? 4 1 7 4 thissample singlecolmn areyourprogram ok ? 5 4 5 1 1234 third wrpnxt4 nxt1 DDS KL RLOVRBTBN 22fdfds23fsd24aafdfaa14fsdfR24as34REE44GH54dnxt11sds12 abcde fghij klmno123456789 ? 1 1 1 1 wxyz ? 7 4 4 4 ? 32 3 15 2 ProblemC CyberGuardian Inthegoodolddays theInternetwasfreefromfearsandterrorism Peopledidnothavetoworryaboutanycybercriminalsormad computerscientists Todayhoweveryouarefacingatrociouscrackerswhereveryouare unlessbeingdisconnectedYouhavetoprotectyourselvesagainsttheirattacks Countinguponyourexcellenttalentforsoftwareconstructionand strongsenseofjusticeyouareinvitedtoworkasacyber guardianYourultimatemissionistocreateaperfectfirewallsystem thatcancompletelyshutoutanyintrudersinvadingnetworks andprotectchildrenfromharmfulinformationexposedontheNetHowever itisextremelydifficultandnonehaveeverachievedit beforeAsthefirststepinsteadyouarenowrequestedto writeasoftwaresimulatorundermuchsimplerassumptions Ingeneralafirewallsystemworksattheentranceofa localnetworkofanorganizationand enforcesitslocaladministrativepolicyItreceivesbothin boundandoutboundpacketsnotedatatransmittedontheNetaredivided intosmallsegmentscalledpacketsandcarefullyinspects themonebyonewhetherornoteachofthemislegal.Thedefinitionofthe legalitymayvaryfromsitetositeordependuponthelocaladministrative policyofanorganization.Yoursimulatorshouldaccept datarepresentingnotonlyreceivedpacketsbutalsothelocaladministrativepolicy Forsimplicityinthisproblemweassumethateachnetworkpacketconsistsofthreefields itssourceaddressdestinationaddress andmessagebodyThesourceaddressspecifies thecomputerorappliancethattransmitsthepacketandthedestinationaddress specifiesthecomputerorappliancetowhichthepacketistransmitted Anaddressinyoursimulatorisrepresentedaseightdigits suchas03214567or31415926 insteadofusingthestandardnotationof IPaddressessuchas19216811Administrativepolicyis describedinfilteringrules eachofwhichspecifiessomecollectionofsource destinationaddresspairsanddefinesthosepacketswith thespecifiedaddresspairseitherlegalorillegal Input Theinputconsistsofseveraldatasets eachofwhichrepresentsfilteringrulesandreceivedpacketsinthefollowingformat nm rule1 rule2 rulen packet1 packet2 packetm Thefirstlineconsistsoftwononnegative integersnandm Ifbothnandmarezeros,thismeanstheendofinputOtherwise nlineseachrepresentingafilteringruleandmlines eachrepresentinganarrivingpacketfollowinthisorderYoumayassumethatn andmarelessthanorequalto1024 Eachruleiisinoneofthefollowingformats permitsourcepatterndestinationpattern denysourcepatterndestinationpattern Asourcepatternordestinationpatternisacharacterstringoflengtheight whereeachcharacteriseitheradigit0to9ora wildcardcharacterForinstance15matchesanyaddress whosefirstandfifthdigitsare1and5respectivelyIn generalawildcardcharactermatchesanysingledigitwhileadigitmatchesonlyitself Withthekeywordspermitanddeny filteringrulesspecifylegalandillegalpacketsrespectivelyThatis ifthesourceand destinationaddressesofapackedarematchedwithsourcepatternanddestinationpattern respectivelyitispermittedtopassthe firewallortherequestisdeniedaccordingtothekeyword Notethatapermitruleandadenyrulecancontradictsincetheymay sharethesamesourceanddestinationaddresspair Forthepurposeofconflictresolutionwedefineapriorityruleruleihasahigher priorityoverrulejifandonlyifijForcompleteness wedefinethedefaultruleanypacketisillegalunlessbeingexplicitlyspecified legalbysomegivenrule Apacketisinthefollowingformat sourceaddressdestinationaddressmessagebody Eachofthefirsttwoisacharacterstringoflengtheightthatconsistssolelyofdigits Thelastoneisacharacterstringconsisting solelyofalphanumericcharactersatozAtoZand0to9 Neitherwhitespacesnorspecialcharacterscanoccurina messagebodyYoumayassumethatitisnotemptyandthatitslengthisatmost50 Youmayalsoassumethatthereisexactlyonespace characterbetweenanytwoadjacentfieldsinaninputlinerepresentingarule or apacket Output Foreachdatasetprintthenumberoflegalpacketsinthefirstline followedbyalllegalpacketsinthesameorderastheyoccurin thedatasetEachpacketmustbewrittenexactlyinoneline Ifthedatasetincludestwopacketsconsistingofthesamesourceand destinationaddressesandthesamemessagebody youshouldconsiderthemdifferentpacketsandsotheymustbewrittenin differentlines.Anyextrawhitespacesorextraemptylinesmustnotbewritten SampleInput 25 permit1921681234 deny192168990123435 1921671111233340HiIamACracker 1921689101234345Hello 1921689901234345HiIamAlsoACracker 1921680911200340World 0000000099999999TheEndOfTheWorld 12 permit1234567823456789 1921689101234345Hello 1234567823456789Hello 00 OutputfortheSampleInput 2 1921689101234345Hello 1921680911200340World 1 1234567823456789Hello ? 25 2 24 2 AincludeIBstdioDhC AincludeIBsysQtypesDhC AincludeIBsysQsocketDhC AincludeIBnetinetQinDhC AincludeIBstringDhC AdefineIWQLENI5 voidIerrorEcharIVsF G IIperrorEsFIJ IIexitE1FIJ H intISetupForClientEcharIVipLIcharIVsprotoLIcharIVportnumF G IIintIfdIJ IIstructIsockaddrKinIcliIJ IIintItypeLIprotoIJ IImemsetENcliL0LsizeofEcliFFIJ IIcliDsinKfamilyIRIAFKINETIJ IIcliDsinKaddrDsKaddrIRIinetKaddrEipFIJ IIcliDsinKportIRIhtonsEatoiEportnumFFIJ IIifEOIstrcmpEsprotoLPtcpPFFIG IIIItypeIRISOCKKSTREAMIJIprotoIRIIPPROTOKTCPIJ IIH IIelseIG IIIItypeIRISOCKKDGRAMIJIprotoIRIIPPROTOKUDPIJ IIH IIfdIRIsocketEAFKINETLItypeLIprotoFIJ IIifEfdIBI0FIerrorEPcanInotIopenIsocketPFIJ IIifEbindEfdLIEstructIsockaddrIVFNcliLIsizeofEcliFFIBI0F IIIIerrorEPcanInotIconnectPFIJ IIifEtypeIRRISOCKKSTREAMINNIlistenEfdLIWQLENFF IIIIerrorEPcanInotIsetIlistenPFIJ IIreturnIfdIJ H voidIServerProcessEcharIVinLIFILEIVsfpF G IIintIcLIlcapLIscapLInumsLIothersIJ IIforElcapRscapRnumsRothersR0IJIEcIRIVinXXFIORIZSnZIJIFIG IIIIifEZaZIBRIcINNIcIBRIZzZFIXXscapIJ IIIIelseIifEZAZIBRIcINNIcIBRIZZZFIXXlcapIJII IIIIelseIifEZ0ZIBRIcINNIcIBRIZ9ZFIXXnumsIJ IIIIelseIXXothersIJ IIH IIfprintfEsfpLIPDLCAPRYdLSCAPRYdLNUMSRYdLothersRYdSnPL IIlcapLscapLnumsLothersFIJ H mainEintIargcLIcharIVargvUTF G IIintIiLIfdLIlLIdfdLIclenLddIJ IIFILEIVsfpLIVrfpIJ IIstructIsockaddrKinIcliIJ IIcharIrequestU1024TJI II IIfdIRISetupForClientEargvU1TLIPtcpPLIargvU2TFIJ IIprintfEPserverWIwaitngIforIclientSnPFIJ IIclenIRIsizeofEcliFIJ IIdfdIRIacceptEfdLIEstructIsockaddrIVFNcliLINclenFIJ IIifEdfdIBI0FIerrorEPacceptIerrorPFIJ IIprintfEPserverWIconnectedIfromIYxSnPLIntohlEcliDsinKaddrDsKaddrFFIJ IIrfpIRIfdopenEdfdLIPrPFIJIsfpIRIfdopenEdfdLIPwPFIJI IIifErfpIRRINULLI||IsfpIRRINULLFIerrorEPcanInotIfdopenPFIJ IIdoIG IIIIifEfgetsErequestLIsizeofErequestFLIrfpFIRRINULLFIbreakIJ IIIIifErequestU0TIRRIZQZFI IIIIIIfputsEPQSnPLIsfpFIJ IIIIelseI IIIIIIServerProcessErequestX1LIsfpFIJI IIIIfflushEsfpFIJ IIHIwhileErequestU0TIORIZQZFIJ IIfcloseEsfpFIJIIfcloseErfpFIJ IIcloseEdfdFIJ IIcloseEfdFIJ H ? 0