哪位大神能不用运行看出来下面的程序打印的是什么?
c语言吧
全部回复
仅看楼主
level 11
娑婆诃💖 楼主
#include <stdio.h>
unsigned short a[8]={0x0180,0x0240,0x0660,0x0c30,0x1ff8,0x300c,0x6006,0xf00f};
int b[16];
void depress(unsigned short n)
{
int i;
unsigned short m;
for (i=15;i>=0;i--)
{
m=n>>i;
m&=0x1;
if (m)
b[15-i]=1;
else
b[15-i]=0;
}
}
int main()
{
int row,col,i;
printf("\n");
for (row=0;row<8;row++)
for (col=0;col<16;col++)
{
depress(a[row]);
if (b[col] ==0 )
printf(" ");
else
printf("*");
if (col==15)
printf("\n");
}
return 0;
}
还有就是怎么优化?
2018年04月18日 20点04分 1
level 15
没必要单门depress,直接循环右移就行了
2018年04月18日 20点04分 2
脑容量不够,只能分开写。话说depress该怎么优化?
2018年04月18日 20点04分
level 11
娑婆诃💖 楼主
我看出来了,depress可以放到外层循环,这样总共只要执行8次
还有可以一次性把数据都depress完成,会更快一些
depress函数不知道怎么优化?
2018年04月18日 20点04分 3
目测没法优化[汗]
2018年04月18日 22点04分
回复 三枝💕葉留佳 :纳尼!!!
2018年04月18日 22点04分
我觉得还是有搞头的,用什么办法把m优化掉
2018年04月18日 22点04分
回复 娑婆诃💖 :不然,因为输出图形需要O(row*col)
2018年04月18日 23点04分
level 11
娑婆诃💖 楼主
有人吗
2018年04月19日 03点04分 4
level 14
可以去掉depress
A对称
内层循环中
if改成a[]& 1
a[]右移一位
2018年04月19日 03点04分 5
好主意,直接处理二进制,不用还原成数组了
2018年04月19日 03点04分
回复 娑婆诃💖 :如果不想改变数组中的值,可以加一个只有一位为1的变量,&,然后变量移位
2018年04月19日 03点04分
level 11
娑婆诃💖 楼主
话说把数组做大,应该可以显示汉字
2018年04月19日 03点04分 6
level 11
娑婆诃💖 楼主
重写了一边结果不对了[狂汗]
#include <stdio.h>
unsigned short a[8]={0x0180,0x0240,0x0660,0x0c30,0x1ff8,0x300c,0x6006,0xf00f};
struct UINT64
{
unsigned int low;
unsigned int high;
};
void main()
{
struct UINT64 begin,end;
int row,col;
_asm
{
rdtsc
mov begin.low,eax
mov begin.high,edx
}
/**************begin****************/
printf("\n");
for (row=0;row<8;row++)
{
for (col=0;col<16;col++)
{
if ( (a[row]>>(15-col))&0x1 == 0 )
printf(" ");
else
printf("*");
if (col==15)
printf("\n");
}
}
/*************end*********************/
_asm
{
rdtsc
mov end.low,eax
mov end.high,edx
}
printf("%010d,%010d ticks took\n",end.high-begin.high,end.low-begin.low);
}
2018年04月19日 06点04分 7
1