2018-Ninth Blue Bridge Cup Individual Provincial Competition (Software) Zhenti C University Group B 2. Clear code

Clear code

The glyphs of Chinese characters exist in the font library. Even today, the 16-dot font library is still widely used.
The 16-dot font library regards each Chinese character as 16x16 pixel information. And record this information in bytes.
One byte can store 8 bits of information, and 32 bytes can store the shape of a Chinese character.
Convert each byte to binary representation, 1 means ink, 0 means background color. Each line has 2 bytes, a
total of 16 lines, the layout is:

1st byte, 2nd byte
3rd byte, 4th byte
...
31st byte, 32nd byte

This question is to give you a piece of information composed of multiple Chinese characters. Each Chinese character is represented by 32 bytes. The value of the byte as a signed integer is given here.

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

This piece of information is (a total of 10 Chinese characters):

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

Note: What needs to be submitted is an integer, do not fill in any extra content.

Analysis: We need to master the rules for converting signed integers into 8-bit binary numbers:

  • positive number:
  • Classical remainder, reverse order, high bit complement 0 to get the eight-bit original code (equal to its complement and inverse code) (the highest bit is 0, representing a positive sign)
  • negative number:
  • Take the absolute value first
  • 8-bit original code of absolute value
  • Invert all digits to get one's complement (0 becomes 1, 1 becomes 0)
  • Add one to the complement to get the eight-bit binary code of a negative number (every binary enters one) (the highest bit is 1, which represents a negative sign)
#include<bits/stdc++.h>//万能头文件
using namespace std;
void shift(int n){
    
    
	int bit[9],flag=0;
	if(n<0){
    
    
		flag=1;
		n=-n;
	}//取绝对值
	for(int i=7;i>=0;i--){
    
    
		bit[i]=n%2;
		n/=2;//实现取余并倒序
	}
	if(flag){
    
    
		for(int i=7;i>=0;i--){
    
    
			if(bit[i]==1)
				bit[i]=0;
			else
				bit[i]=1;
		}//得反码
		bit[7]++;//加一取补码
		for(int i=7;i>=0;i--){
    
    
			if(bit[i]==2){
    
    //进位
				bit[i]=0;
				bit[i-1]++;
			}
		}
	}
	for(int i=0;i<8;i++){
    
    
		if(bit[i]==0)
			cout<<' ';
		else
			cout<<'*';
	}
}
int main(){
    
    
	int n=10;
	while(n--){
    
    
		for(int i=0;i<16;i++){
    
    
			int a,b;
			cin>>a;
			shift(a);
			cin>>b;
			shift(b);//一行一个汉字,对应32字节
			cout<<endl;//每两个数字出现一次换行,从上到下构建汉字
		}
		cout<<endl;//汉字上下有一定间隔,输出美观
	}
	return 0;
}

Output:

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
     *
     *
     *
     *    *
************
     *    *
     *    *
     *    *
     *    *
     *    *
    *     *
    *     *
   *      *   *
   *      *   *
  *        ****
**

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

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

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

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

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

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

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

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



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


       **
      ****
       **

Finally, you can get the answer as required

Guess you like

Origin blog.csdn.net/interestingddd/article/details/114444523