本题为填空题,只需要算出结果后,在代码中使用输出语句将所填结果输出即可。 汉字的字形存在于字库中,即便在今天,16 点阵的字库也仍然使用广泛。 16 点阵的字库把每个汉字看成是 16×16 个像素信息。并把这些信息记录在字节中。 一个字节可以存储 88 位信息,用 32 个字节就可以存一个汉字的字形了。 把每个字节转为 2 进制表示,1 表示墨迹,0 表示底色。每行 2 个字节,一共 16 行,布局是: 第 1 字节,第 2 字节 第 3 字节,第 4 字节 .... 第 31 字节, 第 32 字节 这道题目是给你一段多个汉字组成的信息,每个汉字用 32 个字节表示,这里给出了字节作为有符号整数的值。 题目的要求隐藏在这些信息中。你的任务是复原这些汉字的字形,从中看出题目的要求,并根据要求填写答案。 这段信息是(一共 10 个汉字): 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 copy 运行限制 最大运行时间:1s 最大运行内存: 128M
主要写的是转换二进制输出的代码:中间的注释部分是真正的题目答案
import java.util.Scanner;
public class 明码 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
int n = 0;
while (scan.hasNext()) {
while (n<2){
int[] number = conversionTwo(scan.nextInt());
for (int i : number) {
if (i == 0) {
System.out.print(" ");
}
if (i == 1) {
System.out.print(i);
}
}
n++;
}
n=0;
System.out.println();
}
scan.close();
}
// int a = 1;
// for(int i=0;i<9;i++){
// a*=9;
// }
// System.out.print(a);
public static int[] conversionTwo(int value){
int[] number=new int[8];
if(value == 0){
return number;
}else if (value<0){
int num = -value;
if (num>127){
return number;
}
int i = 0;//计数器
int a = num;//整除
int r = 0;//余数
int[] two = new int[9];//暂存数组
two[0] = 1;
while (a != 0){
r = a%2;
a = a/2;
i++;
two[i] = r;
}
for (int j=two.length-1, k=0;j>0;j--,k++){
number[k]=(two[j]+1)%2;//逐位取反
}
int carry = 0;//进位
for (int j=number.length-1;j>=0;j--){//末位+1
if (j==number.length-1){
if (number[j]==0) {
number[j] = 1;
return number;
}else {
number[j] = 0;
carry=1;
continue;
}
}else {
if (number[j]!=0){
if (carry>0){
number[j]=0;
}
}else {
if (carry>0){
number[j]=1;
carry=0;
}
}
continue;
}
}
}else {
if (value>127){
return number;
}
int i = 0;//计数器
int a = value;//整除
int r = 0;//余数
int[] two=new int[9];//暂存数组
two[0]=0;
while (a!=0){
r=a%2;
a=a/2;
i++;
two[i]=r;
}
for (int j=two.length-1, k=0;j>0;j--,k++){
number[k]=two[j];
}
}
return number;
}
}
运行截图如下:
代码是自己写的,所以可能写的不是很好~大家多多包容。