bitset function (binary processing)

//The 9th Blue Bridge Cup in 2018 [C++ Provincial Competition Group B] [Second Question: Clear Code]

#include <bits/stdc++.h>
using namespace std;
int main() {
    
    
	int n,m;
	string str1,str2;
	while(cin>>n>>m) {
    
    
		bitset<8> b(n); //将一个数字转换为一个长度为n的二进制串
		str1 = b.to_string();//将b转化为字符串类型
		cout<<str1; 
		int len1 = str1.length();
		for(int i=0; i<len1; i++) {
    
    
			if(str1[i] == '0')
				printf(" ");
			else printf("*");
		}
		bitset<8> c(m);
		str2 = c.to_string();
		cout<<str2;
		int len2 = str2.length();
		for(int i=0; i<len2; i++) {
    
     
			if(str2[i] == '0')printf(" ");
			else printf("*");
		}
		printf("\n");
	}
	return 0;
}

/*
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 glyph of a Chinese character.

Convert each byte to binary representation, 1 for ink, 0 for background color. 2 bytes per line, a total of 16 lines, the layout is:
1st byte, 2nd byte
, 3rd byte, 4th byte
...
31st byte, 32nd byte

This title is to give you a piece of information composed of multiple Chinese characters, each Chinese character is represented by 32 bytes, and the value of the bytes as a signed integer is given here.
The title's requirements are hidden in this information. Your task is to restore the glyphs of these Chinese characters, find out 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
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 redundant content.
*/

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325861936&siteId=291194637