2018 Blue Bridge Cup clear code problem Java detailed explanation (one of the solutions, the complete code is at the end of the article)

Title:

This question is a blank filling question. You only need to calculate the result and use the output statement in the code to output the filled result.

The glyphs of Chinese characters exist in the font library. Even today, the 16 # dot matrix font library is still widely used.

16. The font of dot matrix regards each Chinese character as 16 × 16 pixel information. And record this information in bytes.

One byte can store 8 bits of information, and 32 bytes can store the font of a Chinese character. Convert each byte to binary representation, 1 for ink and 0 for background color. 2 bytes per line, 16 lines in total. The layout is:

1st byte, 2nd byte

3rd byte, 4th byte

....

31st byte, 32nd byte

This topic is to give you a piece of information composed of multiple Chinese characters. Each Chinese character is represented by 32} bytes. Here is the value of bytes as signed integers.

The requirements of the topic are hidden in this information. Your task is to restore the glyphs of these Chinese characters, see the requirements of the questions, and fill in the answers according to the requirements.

This message is (10 Chinese characters in total):

4 0 4 0 4 0 4 32 -1 -16 4 32 4 32 4 32 4 32 4 32 8 32 8 32 16 34 16 34 32 30 -64 0 
4 0 4 0 4 0 4 32 -1 -16 4 32 4 32 4 32 4 32 4 32 8 32 8 32 16 34 16 34 32 30 -64 0 
0 -128 64 -128 48 -128 17 8 1 -4 2 8 8 80 16 64 32 64 -32 64 32 -96 32 -96 33 16 34 8 36 14 40 4 
4 0 3 0 1 0 0 4 -1 -2 4 0 4 16 7 -8 4 16 4 16 4 16 8 16 8 16 16 16 32 -96 64 64 
16 64 20 72 62 -4 73 32 5 16 1 0 63 -8 1 0 -1 -2 0 64 0 80 63 -8 8 64 4 64 1 64 0 -128 
0 16 63 -8 1 0 1 0 1 0 1 4 -1 -2 1 0 1 0 1 0 1 0 1 0 1 0 1 0 5 0 2 0 
2 0 2 0 7 -16 8 32 24 64 37 -128 2 -128 12 -128 113 -4 2 8 12 16 18 32 33 -64 1 0 14 0 112 0 
1 0 1 0 1 0 9 32 9 16 17 12 17 4 33 16 65 16 1 32 1 64 0 -128 1 0 2 0 12 0 112 0 
0 0 0 0 7 -16 24 24 48 12 56 12 0 56 0 -32 0 -64 0 -128 0 0 0 0 1 -128 3 -64 1 -128 0 0 
 

Detailed explanation process:

There are many ways to solve this problem. Arrays and strings are used here.

Idea:

  1. According to the analysis of the title and the given data, we can get the binary code corresponding to each byte of the 32 bytes of each word. Then arrange them into 16 according to the layout of 16 dot matrix × 16 matrix, then each word will be displayed.
  2. If 8 bits are used to represent a byte, according to the layout, one line is two bytes, 32 bytes need 16 lines, and each line has 16 bits.
  3. First convert the given integer data into binary code, and then arrange it to get the result.

Specific steps:

  1. Since one byte can store 8-bit information, 32 bytes can store a Chinese character font. Convert each byte into binary representation, 2 bytes per line, a total of 16 lines. A 16 is required at this time × 2 to store 32-bit bytes of each Chinese character, and the other 16 × The two-dimensional array b of 2 stores its corresponding binary code.
  2. To store all data, you need to create a three-dimensional array c to sort out the given data (as follows):

    {{4, 0} ,{4, 0},{ 4, 0}, {4, 32},{ -1, -16},{ 4, 32},{ 4 ,32} ,{4 ,32},{ 4, 32},{ 4, 32},{ 8, 32},{ 8, 32},{ 16, 34}, {16, 34}, {32, 30}, {-64 ,0} },

    {{16, 64},{ 16, 64},{ 34, 68},{ 127 ,126},{ 66, -124},{67, 4},{ 66, 4},{ 66 ,-124},{ 126, 100},{ 66, 36} ,{66 ,4 },{66, 4},{ 66, 4},{126 ,4} ,{66,40},{ 0, 16} },

    {{4, 0} ,{4, 0},{ 4, 0}, {4, 32},{ -1, -16},{ 4, 32},{ 4 ,32} ,{4 ,32},{ 4, 32},{ 4, 32},{ 8, 32},{ 8, 32},{ 16, 34}, {16, 34}, {32, 30}, {-64 ,0} },

    {{0 ,-128},{ 64, -128},{ 48, -128} ,{17, 8 },{1 ,-4} ,{2 ,8},{8, 80}, {16, 64}, {32, 64},{ -32, 64}, {32, -96},{32, -96},{ 33, 16} ,{34, 8}, {36, 14},{ 40, 4 }},

    {{4, 0},{ 3 ,0} ,{1 ,0} ,{0 ,4} ,{-1, -2},{ 4, 0},{ 4, 16}, {7, -8},{ 4 ,16}, {4, 16},{4 ,16},{ 8 ,16} ,{8 ,16}, {16, 16},{ 32, -96}, {64, 64 }},

    {{16, 64} ,{20, 72}, {62, -4}, {73 ,32} ,{5 ,16},{ 1 ,0} ,{63, -8} ,{1, 0},{ -1, -2}, {0, 64},{ 0, 80},{ 63 ,-8},{ 8 ,64} ,{4 ,64} ,{1 ,64}, {0, -128 }},

    {{0, 16},{ 63, -8} ,{1 ,0} ,{1 ,0} ,{1 ,0} ,{1 ,4}, {-1, -2}, {1, 0 },{1 ,0} ,{1 ,0} ,{1 ,0}, {1, 0}, {1, 0},{ 1, 0},{ 5, 0},{ 2, 0 }},

    {{2, 0},{ 2, 0}, {7, -16},{ 8, 32}, {24, 64}, {37, -128} ,{2 ,-128},{ 12 ,-128},{ 113, -4},{ 2, 8} ,{12 ,16}, {18, 32}, {33, -64} ,{1 ,0} ,{14 ,0},{ 112, 0 }},

    {{1, 0} ,{1, 0}, {1, 0},{ 9 ,32},{ 9, 16}, {17, 12}, {17, 4},{ 33, 16},{ 65, 16},{ 1, 32}, {1, 64}, {0 ,-128},{ 1 ,0} ,{2 ,0} ,{12, 0}, {112, 0 }},

    {{0, 0 },{0, 0}, {7, -16}, {24, 24}, {48, 12}, {56, 12},{ 0, 56},{ 0, -32}, {0, -64}, {0, -128 },{0,0},{0, 0},{ 1 ,-128},{ 3, -64}, {1 ,-128},{ 0, 0 }}

  3. At this time, some binary strings converted are less than 8 bits (0 = < given number < 128), and some are more than 8 bits (negative number). You need to process the string. Since 1 represents ink and 0 represents background color, 0 can be used as a substitute for less than 8 bits to make its output meet 8 bits. For more than 8 bits, only the last 8 bits need to be taken (the first 24 bits are 1).

                     if (b[i][k].length()<8) 
    					{
    						for (int j = 0; j < 8-b[i][k].length(); j++) 
    						{
    							System.out.print(0);//Those with less than 8 bits shall be supplemented with 0
    						}
    						System.out.print(b[i][k]);//Output binary string
    					}
    					else if (b[i][k].length()>8) 
    					{
    						System.out.print(b[i][k].substring(24));//Output the last 8 bits
    					}
    					else 
    					{
    						System.out.print(b[i][k]);//Output binary string
    					}

result:

As shown in the figure:

At this time, we see the requirement of the topic: "how much is the ninth power of nine?". Through the calculation=387 420 489

Full code:

public class Change {
	public static void main(String[] args) {
		//Store binary codes converted by numbers
		String[][] b=new String[16][2];
		//Store 32-bit bytes (digits) of each Chinese character
		int [] []array=new int[16][2];
		//Store the given information
		int [][][]c=new int[][][] {{{4, 0} ,{4, 0},{ 4, 0}, {4, 32},{ -1, -16},{ 4, 32},{ 4 ,32} ,{4 ,32},{ 4, 32},{ 4, 32},{ 8, 32},{ 8, 32},{ 16, 34}, {16, 34}, {32, 30}, {-64 ,0} },

                 {{16, 64},{ 16, 64},{ 34, 68},{ 127 ,126},{ 66, -124},{67, 4},{ 66, 4},{ 66 ,-124},{ 126, 100},{ 66, 36} ,{66 ,4 },{66, 4},{ 66, 4},{126 ,4} ,{66,40},{ 0, 16} },

                 {{4, 0} ,{4, 0},{ 4, 0}, {4, 32},{ -1, -16},{ 4, 32},{ 4 ,32} ,{4 ,32},{ 4, 32},{ 4, 32},{ 8, 32},{ 8, 32},{ 16, 34}, {16, 34}, {32, 30}, {-64 ,0} },

                 {{0 ,-128},{ 64, -128},{ 48, -128} ,{17, 8 },{1 ,-4} ,{2 ,8},{8, 80}, {16, 64}, {32, 64},{ -32, 64}, {32, -96},{32, -96},{ 33, 16} ,{34, 8}, {36, 14},{ 40, 4 }},

                 {{4, 0},{ 3 ,0} ,{1 ,0} ,{0 ,4} ,{-1, -2},{ 4, 0},{ 4, 16}, {7, -8},{ 4 ,16}, {4, 16},{4 ,16},{ 8 ,16} ,{8 ,16}, {16, 16},{ 32, -96}, {64, 64 }},

                 {{16, 64} ,{20, 72}, {62, -4}, {73 ,32} ,{5 ,16},{ 1 ,0} ,{63, -8} ,{1, 0},{ -1, -2}, {0, 64},{ 0, 80},{ 63 ,-8},{ 8 ,64} ,{4 ,64} ,{1 ,64}, {0, -128 }},

                 {{0, 16},{ 63, -8} ,{1 ,0} ,{1 ,0} ,{1 ,0} ,{1 ,4}, {-1, -2}, {1, 0 },{1 ,0} ,{1 ,0} ,{1 ,0}, {1, 0}, {1, 0},{ 1, 0},{ 5, 0},{ 2, 0 }},

                 {{2, 0},{ 2, 0}, {7, -16},{ 8, 32}, {24, 64}, {37, -128} ,{2 ,-128},{ 12 ,-128},{ 113, -4},{ 2, 8} ,{12 ,16}, {18, 32}, {33, -64} ,{1 ,0} ,{14 ,0},{ 112, 0 }},

                 {{1, 0} ,{1, 0}, {1, 0},{ 9 ,32},{ 9, 16}, {17, 12}, {17, 4},{ 33, 16},{ 65, 16},{ 1, 32}, {1, 64}, {0 ,-128},{ 1 ,0} ,{2 ,0} ,{12, 0}, {112, 0 }},

                 {{0, 0 },{0, 0}, {7, -16}, {24, 24}, {48, 12}, {56, 12},{ 0, 56},{ 0, -32}, {0, -64}, {0, -128 },{0,0},{0, 0},{ 1 ,-128},{ 3, -64}, {1 ,-128},{ 0, 0 }}};
		for (int m = 0; m < c.length; m++) //Traverse the given information
		{
			array=c[m];
			for (int i = 0; i < 16; i++) //Traverse the 32-bit bytes of each Chinese character
			{
				for (int k = 0; k < 2; k++)
				{
					b[i][k]=Integer.toBinaryString(array[i][k]);//Convert each byte to binary
					if (b[i][k].length()<8) 
					{
						for (int j = 0; j < 8-b[i][k].length(); j++) 
						{
							System.out.print(0);//Those with less than 8 bits shall be supplemented with 0
						}
						System.out.print(b[i][k]);//Output binary string
					}
					else if (b[i][k].length()>8) 
					{
						System.out.print(b[i][k].substring(24));//Output the last 8 bits
					}
					else 
					{
						System.out.print(b[i][k]);//Output binary string
					}
				}
				System.out.println();
					
			}
			System.out.println("****************");//Distinguish each word
		}		
	}
}

 

 

 

 

 

 

 

 

 

 

      

Keywords: Java Eclipse IDEA

Added by neroag on Mon, 07 Mar 2022 16:48:18 +0200