Cryptographic Code

<!--[if gte mso 9]><xml> <o:OfficeDocumentSettings> <o:AllowPNG/> </o:OfficeDocumentSettings> </xml><![endif]-->

<!--[if gte mso 9]><xml> <w:WordDocument> <w:View>Normal</w:View> <w:Zoom>0</w:Zoom> <w:TrackMoves/> <w:TrackFormatting/> <w:PunctuationKerning/> <w:DrawingGridVerticalSpacing>7.8 磅</w:DrawingGridVerticalSpacing> <w:DisplayHorizontalDrawingGridEvery>0</w:DisplayHorizontalDrawingGridEvery> <w:DisplayVerticalDrawingGridEvery>2</w:DisplayVerticalDrawingGridEvery> <w:ValidateAgainstSchemas/> <w:SaveIfXMLInvalid>false</w:SaveIfXMLInvalid> <w:IgnoreMixedContent>false</w:IgnoreMixedContent> <w:AlwaysShowPlaceholderText>false</w:AlwaysShowPlaceholderText> <w:DoNotPromoteQF/> <w:LidThemeOther>EN-US</w:LidThemeOther> <w:LidThemeAsian>KO</w:LidThemeAsian> <w:LidThemeComplexScript>X-NONE</w:LidThemeComplexScript> <w:Compatibility> <w:SpaceForUL/> <w:BalanceSingleByteDoubleByteWidth/> <w:DoNotLeaveBackslashAlone/> <w:ULTrailSpace/> <w:DoNotExpandShiftReturn/> <w:AdjustLineHeightInTable/> <w:BreakWrappedTables/> <w:SnapToGridInCell/> <w:WrapTextWithPunct/> <w:UseAsianBreakRules/> <w:DontGrowAutofit/> <w:SplitPgBreakAndParaMark/> <w:EnableOpenTypeKerning/> <w:DontFlipMirrorIndents/> <w:OverrideTableStyleHps/> <w:UseFELayout/> </w:Compatibility> <m:mathPr> <m:mathFont m:val="Cambria Math"/> <m:brkBin m:val="before"/> <m:brkBinSub m:val="&#45;-"/> <m:smallFrac m:val="off"/> <m:dispDef/> <m:lMargin m:val="0"/> <m:rMargin m:val="0"/> <m:defJc m:val="centerGroup"/> <m:wrapIndent m:val="1440"/> <m:intLim m:val="subSup"/> <m:naryLim m:val="undOvr"/> </m:mathPr></w:WordDocument> </xml><![endif]--><!--[if gte mso 9]><xml> <w:LatentStyles DefLockedState="false" DefUnhideWhenUsed="true" DefSemiHidden="true" DefQFormat="false" DefPriority="99" LatentStyleCount="267"> <w:LsdException Locked="false" Priority="0" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Normal"/> <w:LsdException Locked="false" Priority="9" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="heading 1"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 2"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 3"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 4"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 5"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 6"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 7"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 8"/> <w:LsdException Locked="false" Priority="9" QFormat="true" Name="heading 9"/> <w:LsdException Locked="false" Priority="39" Name="toc 1"/> <w:LsdException Locked="false" Priority="39" Name="toc 2"/> <w:LsdException Locked="false" Priority="39" Name="toc 3"/> <w:LsdException Locked="false" Priority="39" Name="toc 4"/> <w:LsdException Locked="false" Priority="39" Name="toc 5"/> <w:LsdException Locked="false" Priority="39" Name="toc 6"/> <w:LsdException Locked="false" Priority="39" Name="toc 7"/> <w:LsdException Locked="false" Priority="39" Name="toc 8"/> <w:LsdException Locked="false" Priority="39" Name="toc 9"/> <w:LsdException Locked="false" Priority="35" QFormat="true" Name="caption"/> <w:LsdException Locked="false" Priority="10" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Title"/> <w:LsdException Locked="false" Priority="1" Name="Default Paragraph Font"/> <w:LsdException Locked="false" Priority="11" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Subtitle"/> <w:LsdException Locked="false" Priority="22" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Strong"/> <w:LsdException Locked="false" Priority="20" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Emphasis"/> <w:LsdException Locked="false" Priority="59" SemiHidden="false" UnhideWhenUsed="false" Name="Table Grid"/> <w:LsdException Locked="false" UnhideWhenUsed="false" Name="Placeholder Text"/> <w:LsdException Locked="false" Priority="1" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="No Spacing"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading Accent 1"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List Accent 1"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid Accent 1"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1 Accent 1"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2 Accent 1"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1 Accent 1"/> <w:LsdException Locked="false" UnhideWhenUsed="false" Name="Revision"/> <w:LsdException Locked="false" Priority="34" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="List Paragraph"/> <w:LsdException Locked="false" Priority="29" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Quote"/> <w:LsdException Locked="false" Priority="30" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Intense Quote"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2 Accent 1"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1 Accent 1"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2 Accent 1"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3 Accent 1"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List Accent 1"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading Accent 1"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List Accent 1"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid Accent 1"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading Accent 2"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List Accent 2"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid Accent 2"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1 Accent 2"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2 Accent 2"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1 Accent 2"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2 Accent 2"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1 Accent 2"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2 Accent 2"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3 Accent 2"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List Accent 2"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading Accent 2"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List Accent 2"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid Accent 2"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading Accent 3"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List Accent 3"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid Accent 3"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1 Accent 3"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2 Accent 3"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1 Accent 3"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2 Accent 3"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1 Accent 3"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2 Accent 3"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3 Accent 3"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List Accent 3"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading Accent 3"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List Accent 3"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid Accent 3"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading Accent 4"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List Accent 4"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid Accent 4"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1 Accent 4"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2 Accent 4"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1 Accent 4"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2 Accent 4"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1 Accent 4"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2 Accent 4"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3 Accent 4"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List Accent 4"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading Accent 4"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List Accent 4"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid Accent 4"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading Accent 5"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List Accent 5"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid Accent 5"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1 Accent 5"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2 Accent 5"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1 Accent 5"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2 Accent 5"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1 Accent 5"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2 Accent 5"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3 Accent 5"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List Accent 5"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading Accent 5"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List Accent 5"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid Accent 5"/> <w:LsdException Locked="false" Priority="60" SemiHidden="false" UnhideWhenUsed="false" Name="Light Shading Accent 6"/> <w:LsdException Locked="false" Priority="61" SemiHidden="false" UnhideWhenUsed="false" Name="Light List Accent 6"/> <w:LsdException Locked="false" Priority="62" SemiHidden="false" UnhideWhenUsed="false" Name="Light Grid Accent 6"/> <w:LsdException Locked="false" Priority="63" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 1 Accent 6"/> <w:LsdException Locked="false" Priority="64" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Shading 2 Accent 6"/> <w:LsdException Locked="false" Priority="65" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 1 Accent 6"/> <w:LsdException Locked="false" Priority="66" SemiHidden="false" UnhideWhenUsed="false" Name="Medium List 2 Accent 6"/> <w:LsdException Locked="false" Priority="67" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 1 Accent 6"/> <w:LsdException Locked="false" Priority="68" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 2 Accent 6"/> <w:LsdException Locked="false" Priority="69" SemiHidden="false" UnhideWhenUsed="false" Name="Medium Grid 3 Accent 6"/> <w:LsdException Locked="false" Priority="70" SemiHidden="false" UnhideWhenUsed="false" Name="Dark List Accent 6"/> <w:LsdException Locked="false" Priority="71" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Shading Accent 6"/> <w:LsdException Locked="false" Priority="72" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful List Accent 6"/> <w:LsdException Locked="false" Priority="73" SemiHidden="false" UnhideWhenUsed="false" Name="Colorful Grid Accent 6"/> <w:LsdException Locked="false" Priority="19" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Subtle Emphasis"/> <w:LsdException Locked="false" Priority="21" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Intense Emphasis"/> <w:LsdException Locked="false" Priority="31" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Subtle Reference"/> <w:LsdException Locked="false" Priority="32" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Intense Reference"/> <w:LsdException Locked="false" Priority="33" SemiHidden="false" UnhideWhenUsed="false" QFormat="true" Name="Book Title"/> <w:LsdException Locked="false" Priority="37" Name="Bibliography"/> <w:LsdException Locked="false" Priority="39" QFormat="true" Name="TOC Heading"/> </w:LatentStyles> </xml><![endif]--><!--[if gte mso 10]> <style> /* Style Definitions */ table.MsoNormalTable {mso-style-name:普通表格; mso-tstyle-rowband-size:0; mso-tstyle-colband-size:0; mso-style-noshow:yes; mso-style-priority:99; mso-style-parent:""; mso-padding-alt:0cm 5.4pt 0cm 5.4pt; mso-para-margin-top:0cm; mso-para-margin-right:0cm; mso-para-margin-bottom:10.0pt; mso-para-margin-left:0cm; text-align:justify; text-justify:inter-ideograph; line-height:115%; mso-pagination:widow-orphan; font-size:10.0pt; mso-bidi-font-size:11.0pt; font-family:"Malgun Gothic","sans-serif"; mso-ascii-font-family:"Malgun Gothic"; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:"Malgun Gothic"; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:"Malgun Gothic"; mso-hansi-theme-font:minor-latin; mso-font-kerning:1.0pt; mso-fareast-language:KO;} </style> <![endif]-->

Title: Cryptographic Code

 

A country has found out that there is a spy at a broadcasting network within the country. The spy was transmitting video by inserting cryptographic codes into it. It was found that a code consists of numbers that indicate important facilities in the country. Cryptographic code rules are as follows.

 

1.A code consists of 8 numbers.

2.Seven digits in front indicate a product’s unique number, and the last digit indicates verification code.

-Verification code is calculated with the following method.

(sum of numbers in odd position x 3) + sum of numbers in even position + verification codemust be multiples of 10.

When the product unique number is 8801234,

( ( 8 + 0 + 2 + 4 ) x 3 ) + ( 8 + 1 + 3 ) + verification code

= 42 + 12 + verification code

= 54 + verification codemust be multiples of 10, the verification code must be 6.

In other words, 88012346 is the normal cryptographic code, and if the verification code other than 6 is included, they are abnormal cryptographic codes.

 

Company A is trying to develop a scanner that can recognize these cryptographic codes accurately and fast. Performance of the scanner is measured with the following methods.

1.   Cryptographic code information is contained in a rectangular array with 2,000 or less in height and 500 or less in width to be transmitted. One or more code(s) exist in one array (Note: there is no guarantee that all cryptographic codes are normal; abnormal cryptographic code(s) may be included).

2.  An array is composed of hexadecimal numbers. Convert the array to binary numbers and check the cryptographic code information within it.

3. Check the verification code of the cryptographic codes contained and examine whether they are normal cryptographic codes.

4.  After discriminating normal cryptographic codes, print the sum of numbers written in these cryptographic codes.

5.In this case, one with less time spent in total is considered as having a better performance.

 

Specific rules of the cryptographic codes contained in the array are as follows.

1.A cryptographic code consists of 8 numbers and start/end distinguishing lines do not exist.  

2.There are no cases where cryptographic codes are put together (at least one empty block exists around each cryptographic code).

3.There are no cases where a cryptographic code has partial numbers marked. All cryptographic codes consist of 8 numbers.

4.The height of a cryptographic code is 5 ~ 100 blocks.

5.The width of a cryptographic code depends on the line thickness of the cryptographic code, and in case thickness is the thinnest, one number occupies 7 blocks. The method of expressing each numbers in figure is as follows.

0

0

0

0

1

1

0

1

0

0

0

1

1

0

1

0

0

0

1

1

0

1

0

0

0

1

1

0

1

0

0

0

1

1

0

1

3 : 2 : 1 : 1

1

0

0

1

1

0

0

1

0

0

1

1

0

0

1

0

0

1

1

0

0

1

0

0

1

1

0

0

1

0

0

1

1

0

0

1

2 : 2 : 2 : 1

2

0

0

1

0

0

1

1

0

0

1

0

0

1

1

0

0

1

0

0

1

1

0

0

1

0

0

1

1

0

0

1

0

0

1

1

2 : 1 : 2 : 2

3

0

1

1

1

1

0

1

0

1

1

1

1

0

1

0

1

1

1

1

0

1

0

1

1

1

1

0

1

0

1

1

1

1

0

1

1 : 4 : 1 : 1

4

0

1

0

0

0

1

1

0

1

0

0

0

1

1

0

1

0

0

0

1

1

0

1

0

0

0

1

1

0

1

0

0

0

1

1

1 : 1 : 3 : 2

5

0

1

1

0

0

0

1

0

1

1

0

0

0

1

0

1

1

0

0

0

1

0

1

1

0

0

0

1

0

1

1

0

0

0

1

1 : 2 : 3 : 1

6

0

1

0

1

1

1

1

0

1

0

1

1

1

1

0

1

0

1

1

1

1

0

1

0

1

1

1

1

0

1

0

1

1

1

1

1 : 1 : 1 : 4

7

0

1

1

1

0

1

1

0

1

1

1

0

1

1

0

1

1

1

0

1

1

0

1

1

1

0

1

1

0

1

1

1

0

1

1

1 : 3 : 1 : 2

8

0

1

1

0

1

1

1

0

1

1

0

1

1

1

0

1

1

0

1

1

1

0

1

1

0

1

1

1

0

1

1

0

1

1

1

1 : 2 : 1 : 3

9

0

0

0

1

0

1

1

0

0

0

1

0

1

1

0

0

0

1

0

1

1

0

0

0

1

0

1

1

0

0

0

1

0

1

1

3 : 1 : 1 : 2

 

Each number is expressed by ratio of area of white blocks to area of blue blocks. When the length of the cryptographic code gets longer, the length occupied by one number becomes a multiple of 7. For example, when the width increases twofold, 9 can be expressed as below.

9

0

0

0

0

0

0

1

1

0

0

1

1

1

1

0

0

0

0

0

0

1

1

0

0

1

1

1

1

0

0

0

0

0

0

1

1

0

0

1

1

1

1

0

0

0

0

0

0

1

1

0

0

1

1

1

1

0

0

0

0

0

0

1

1

0

0

1

1

1

1

3 : 1 : 1 : 2

 

6. Minimum width of a cryptographic code is 56, and when cryptographic code line gets thicker, the length becomes a multiple of 56. For example, one cryptographic code number uses 14 blocks, the width of a cryptographic code becomes 112. Numbers contained in one cryptographic code all have the same size.

 

Write a program that discriminates normal cryptographic codes after receiving a two-dimensional array that contains cryptographic code information in input.

[Input]
T test cases are given continuously through standard input. (The code for executing input/output has been already provided in the template code you received for reference.)

Two natural numbers N and M are given in the first line of each test case with N being the array height size and M being the array width size (1≤N<2000, 1≤M<500). In the next N lines, M values of the array are given. All values in the array in the problem are hexadecimal numbers.  

 

[Output]
Print answers of each of the test cases in order through standard output, and print “C+” at start of line for each case with C being the case number. In the same line, leave one blank space and print the sum of numbers contained in normal cryptographic codes in the array given in input.

 

 

[Reference]
Each test case is composed as follows (the sample input, and the input used for evaluation have the same structure).

 

Test case

N * M

Width of Cryptographic Code

No. of Cryptographic Code

Group 1

100 * 26

56

1

Group 2

200 * 50

56 ~ 112

2

Group 3

500 * 126

56 ~ 280

5

Group 4

1000 * 250

No limit

No limit

Group 5

2000 * 500

No limit

No limit

 

[Input/output example]
Input (example with two test cases in total. The input to be actually used has more test cases than the example; N and M values follow the reference above.)

2

16 26                ← N, M values, Case 1 starts

00000000000000000000000000

00000000000000000000000000

000000001DB176C588D26EC000

000000001DB176C588D26EC000

000000001DB176C588D26EC000

000000001DB176C588D26EC000

000000001DB176C588D26EC000

000000001DB176C588D26EC000

000000001DB176C588D26EC000

000000001DB176C588D26EC000

000000001DB176C588D26EC000

000000001DB176C588D26EC000

000000001DB176C588D26EC000

000000001DB176C588D26EC000

00000000000000000000000000

00000000000000000000000000

 

 

18 50                ← N, M values, Case 2 starts

00000000000000000000000000000000000000000000000000

00000000000000000000000000000000000000000000000000

000000000000000000000000000196EBC5A316C57800000000

000000000000000000000000000196EBC5A316C57800000000

000000328D1AF6E4C9BB0000000196EBC5A316C57800000000

000000328D1AF6E4C9BB0000000196EBC5A316C57800000000

000000328D1AF6E4C9BB0000000196EBC5A316C57800000000

000000328D1AF6E4C9BB0000000196EBC5A316C57800000000

000000328D1AF6E4C9BB0000000196EBC5A316C57800000000

000000328D1AF6E4C9BB0000000196EBC5A316C57800000000

000000328D1AF6E4C9BB0000000196EBC5A316C57800000000

000000328D1AF6E4C9BB0000000196EBC5A316C57800000000

000000328D1AF6E4C9BB0000000196EBC5A316C57800000000

000000328D1AF6E4C9BB0000000196EBC5A316C57800000000

000000000000000000000000000196EBC5A316C57800000000

000000000000000000000000000196EBC5A316C57800000000

00000000000000000000000000000000000000000000000000

00000000000000000000000000000000000000000000000000

Output

#1 38

#2 48

 

Explanation

Conversion of cryptographic code information of case 1 results in the following.

01110110110001011101101100010110001000110100100110111011

01110110110001011101101100010110001000110100100110111011

01110110110001011101101100010110001000110100100110111011

01110110110001011101101100010110001000110100100110111011

01110110110001011101101100010110001000110100100110111011

01110110110001011101101100010110001000110100100110111011

01110110110001011101101100010110001000110100100110111011

01110110110001011101101100010110001000110100100110111011

01110110110001011101101100010110001000110100100110111011

01110110110001011101101100010110001000110100100110111011

01110110110001011101101100010110001000110100100110111011

01110110110001011101101100010110001000110100100110111011

 

The numbers above indicate the following.

0111011(7) 0110001(5) 0111011(7) 0110001(5) 0110001(5) 0001101(0) 0010011(2) 0111011(7)

 

To check if the verification codes is right, since (7 + 7 + 5 + 2) * 3 + 5 + 5 + 0 + 7 = 80, this is the right cryptographic code. Therefore, the output value of case 1 is 38.

 

When case 2 is computed with the same method,

328D1AF6E4C9BB becomes 14468227, so we can see the verification code is wrong.

196EBC5A316C578 becomes 18694956, so we can see the verification code is right.

Therefore, the output value of case 2 is 48 added only by the value of the right cryptographic code which is 18694956.

 ***************************************************************************************

1
16 26
00000000000000000000000000
00000000000000000000000000
000000001DB176C588D26EC000
000000001DB176C588D26EC000
000000001DB176C588D26EC000
000000001DB176C588D26EC000
000000001DB176C588D26EC000
000000001DB176C588D26EC000
000000001DB176C588D26EC000
000000001DB176C588D26EC000
000000001DB176C588D26EC000
000000001DB176C588D26EC000
000000001DB176C588D26EC000
000000001DB176C588D26EC000
00000000000000000000000000
00000000000000000000000000
18 50
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000
000000000000000000000000000196EBC5A316C57800000000
000000000000000000000000000196EBC5A316C57800000000
000000328D1AF6E4C9BB0000000196EBC5A316C57800000000
000000328D1AF6E4C9BB0000000196EBC5A316C57800000000
000000328D1AF6E4C9BB0000000196EBC5A316C57800000000
000000328D1AF6E4C9BB0000000196EBC5A316C57800000000
000000328D1AF6E4C9BB0000000196EBC5A316C57800000000
000000328D1AF6E4C9BB0000000196EBC5A316C57800000000
000000328D1AF6E4C9BB0000000196EBC5A316C57800000000
000000328D1AF6E4C9BB0000000196EBC5A316C57800000000
000000328D1AF6E4C9BB0000000196EBC5A316C57800000000
000000328D1AF6E4C9BB0000000196EBC5A316C57800000000
000000000000000000000000000196EBC5A316C57800000000
000000000000000000000000000196EBC5A316C57800000000
00000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000

import java.io.FileInputStream;
import java.util.Collection;
import java.util.HashMap;
import java.util.Scanner;

public class CryptographicCode {

    public static final boolean DEBUG = false;

    private static int[][] keyValue = {
            {
                    3, 2, 1, 1
            }, {
                    2, 2, 2, 1
            }, {
                    2, 1, 2, 2
            }, {
                    1, 4, 1, 1
            }, {
                    1, 1, 3, 2
            }, {
                    1, 2, 3, 1
            }, {
                    1, 1, 1, 4
            }, {
                    1, 3, 1, 2
            }, {
                    1, 2, 1, 3
            }, {
                    3, 1, 1, 2
            }
    };

    public static void main(String args[]) throws Exception {
        Scanner sc = new Scanner(System.in);
        sc = new Scanner(new FileInputStream("sample_input2.txt"));

        int T = sc.nextInt();
        int high = 0;
        int width = 0; //字符串 用不到这个宽度;
        HashMap<String, int[]> map = new HashMap<String, int[]>();
        for (int tc = 0; tc < T; tc++) {
            high = sc.nextInt();
            width = sc.nextInt(); // String可以忽略这个width  
            String lastLine = "";
            int sum = 0;

            sc.nextLine();
            for (int i = 0; i < high; i++) {
                String line = sc.nextLine();
                String trimLine = trimEndZero(line); // tirm 0
                if (trimLine.length() <= 0) {
                    lastLine = trimLine; // 更新lastLine;  
                    continue;
                }

                if (!lastLine.equalsIgnoreCase(trimLine)) { // 跟前一行内容不同再进行decode
                    String bianyCode = toBiary(trimLine);
                    checkRule(trimEndZero(bianyCode), map);
                }

                lastLine = trimLine; // 更新lastLine;  
            }

            if (map.size() > 0) {
                Collection<int[]> it = map.values();
                for (int[] p : it) {
                    if (p != null && p.length > 0) {
                        for (int n : p) {
                            sum += n;
                        }
                    }
                }
            }

            System.out.println("#" + (tc + 1) + " " + sum);
            map.clear();
        }
    }

    /**
     * 16进制转二进制字符串;
     * 
     * @param l
     * @return
     */
    private static String toBiary(String l) {
        StringBuffer binaryCode = new StringBuffer();
        for (int i = 0; i < l.length(); i++) {
            int num = Character.getNumericValue(l.charAt(i)); // 十六进制数  
            String iStr2 = Integer.toBinaryString(num); // 2进制格式  
            // for 3 -> 11 -> 0011  
            // 下面很吭爹, java转了之后前面0就被trim了;
            if (1 == iStr2.length()) {
                iStr2 = "000" + iStr2;
            } else if (2 == iStr2.length()) {
                iStr2 = "00" + iStr2;
            } else if (3 == iStr2.length()) {
                iStr2 = "0" + iStr2;
            }
            binaryCode.append(iStr2);
        }

        return binaryCode.toString();
    }

    /**
     * 对二进制字符串进行校验
     * 
     * @param bCode
     * @return
     */
    private static void checkRule(String s, HashMap<String, int[]> map) {
        //分离cryptographic Code;
        if (s == null || s.length() <= 0) {
            return;
        }
        String t = s;
        char last = '9'; //不能会是9;
        int oneNumLen = 0;
        int maxOneNumLen = 0;
        int j = 4;
        int k = 8;
        StringBuffer key = new StringBuffer();
        int num[] = new int[8]; //保存8位数字
        int p[] = new int[4]; //统计4段数量
        for (int i = t.length() - 1; i >= 0; i--) {
            char cur = t.charAt(i);
            if (last != cur) { //有变化--;
                j--;
            }
            if (j < 0) {
                // 已经读取一位数字, 进行decode;
                k--;
                if (k < 0) {
                    break;
                }

                if (k == 0) {
                    if (oneNumLen < maxOneNumLen) {
                        p[0] += (maxOneNumLen - oneNumLen); //给最一位数补全0;;
                    } else if (oneNumLen > maxOneNumLen) {
                        p[0] += (maxOneNumLen - oneNumLen); //给最一位数删除多余0;;
                    }
                    num[k] = decode(p);
                    key.append(num[k]);

                    putMap(key.toString(), num, map, s);
                    num = new int[8];
                    key = new StringBuffer();
                    k = 8;
                } else {
                    num[k] = decode(p);
                    key.append(num[k]);
                }

                //下面可能还有,继续找, 找之前重新初始临时变量;
                j = 3;
                p = new int[4];
                maxOneNumLen = oneNumLen;
                oneNumLen = 0;
            }

            p[j] += 1;
            oneNumLen++;
            last = cur;

            if (i == 0) { //到达行首, 最后一次结果保存起来;
                k--;
                if (k < 0) {
                    break;
                }

                if (k == 0) {
                    if (oneNumLen < maxOneNumLen) {
                        p[0] += (maxOneNumLen - oneNumLen); //给最一位数补全0;;
                    } else if (oneNumLen > maxOneNumLen) {
                        p[0] += (maxOneNumLen - oneNumLen); //给最一位数删除多余0;;
                    }
                }
                num[k] = decode(p);
                key.append(num[k]);
                putMap(key.toString(), num, map, s);
            }
        }
    }

    private static void putMap(String key, int[] num, HashMap<String, int[]> map, String src) {
        //去重,每一个放入map中防止重复;
        //校验下
        /**
         * “( ( 8 + 0 + 2 + 4 ) x 3 ) + ( 8 + 1 + 3 ) + verification code” = “42
         * + 12 + verification code” = “54 + verification code” must be
         * multiples of 10, the verification code must be 6. 18694956 1 + 6 + 4
         * + 5 * 3 + 8 + 9 + 9 + 6
         */
        if (DEBUG) {
            System.out.println("Code : " + src + " : ");
            for (int n : num) {
                System.out.print(n);
            }
            System.out.println("");
        }
        if (num != null && num.length == 8) {
            int a = (num[0] + num[2] + num[4] + num[6]) * 3 + num[1] + num[3] + num[5] + num[7];
            if (a % 10 == 0) {
                map.put(key, num);
                num = new int[8];
            }
        }
    }

    //    }

    /**
     * 找出4段对应的数字
     * 
     * @param p
     * @return
     */
    private static int decode(int[] p) {
        int ret = 0;
        int sum = 0;
        for (int i : p) { //后面三位加起来, 补到7的位数;
            sum += i;
        }
        //        if (sum < 7) {
        //            sum = 7; //最小为7, 有可能比7小,因为p[0]统计不准确;
        //        }

        int b = sum / 7;
        //        if (sum % 7 != 0) {//注意只有p[0]有可能有比较多的0,取整后不影响;
        //            b++;
        //        }

        int[] c = new int[p.length]; //转为最小;
        for (int j = 0; j < p.length; j++) {
            c[j] = p[j] / b;
        }

        //判断后三部分相同就可以了,第一部分不需要比较;
        for (int m = 0; m < keyValue.length; m++) {
            if (keyValue[m][1] == c[1] && keyValue[m][2] == c[2] && keyValue[m][3] == c[3]) {
                ret = m;
                break;
            }

        }
        return ret;
    }

    /**
     * 剪掉尾部的零;
     * 
     * @param line
     * @return
     */
    private static String trimEndZero(String line) {
        String ret = line.replaceFirst("0+$", "");
        int len = ret.length() / 14;
        if (ret.length() % 14 != 0) {
            len++;
        }
        int subIdx = ret.length() - (14 * len) - 1;
        if (subIdx < 0) {
            subIdx = 0;
        }
        return ret.substring(subIdx);
    }
}
 

猜你喜欢

转载自wv1124.iteye.com/blog/2204298