请优化一下吗? [英] Optimize this please?

查看:62
本文介绍了请优化一下吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

typedef unsigned short u16; //可能在您的机器上有所不同

typedef unsigned char u8; //可能在您的机器上有所不同


//假设dst在进入时初始化为零

void packBits(u8 * dst,const u16 * src)< br $> b $ b {

dst [0] | = src [0]> 1;

dst [1] | = src [0]< < 7;

dst [1] | = src [1]> 2;

dst [2] | = src [1]<< 6;

dst [2] | = src [2]> 3;

dst [3] | = src [2]<< 5;

dst [3] | = src [3]> 4;

dst [4] | = src [3]<< 4;

dst [4] | = src [4]> 5;

dst [5] | = src [4]<< 3;

dst [5] | = src [5]> 6;

dst [6] | = src [5]<< 2;

dst [6] | = src [6]> 7;

dst [7] | = src [6]<< 1;

dst [7] | = src [7]> 8;

dst [8] | = src [7];

dst [9] | = src [8]> 1;

dst [10] | = src [8]<< 7;

dst [10] | = src [9]> 2;

dst [11] | = src [9]<< 6;

}


我想用尽可能少的分号复制上面的函数。

。如果你想拿起这个拼图,看看你有多小可以获得它,我们可以比较笔记。


-

要给我发电子邮件,请输入sheltie;在主题中。

typedef unsigned short u16; // may be different on your machine
typedef unsigned char u8; // may be different on your machine

// assume dst is zero initialized upon entry
void packBits( u8* dst, const u16* src )
{
dst[0] |= src[0] >1;
dst[1] |= src[0] << 7;
dst[1] |= src[1] >2;
dst[2] |= src[1] << 6;
dst[2] |= src[2] >3;
dst[3] |= src[2] << 5;
dst[3] |= src[3] >4;
dst[4] |= src[3] << 4;
dst[4] |= src[4] >5;
dst[5] |= src[4] << 3;
dst[5] |= src[5] >6;
dst[6] |= src[5] << 2;
dst[6] |= src[6] >7;
dst[7] |= src[6] << 1;
dst[7] |= src[7] >8;
dst[8] |= src[7];
dst[9] |= src[8] >1;
dst[10] |= src[8] << 7;
dst[10] |= src[9] >2;
dst[11] |= src[9] << 6;
}

I want to duplicate the above function using as few semicolons as
possible. If you want to take up the puzzle, see how small you can get
it and we can compare notes.

--
To send me email, put "sheltie" in the subject.

推荐答案

Daniel T.写道:
Daniel T. wrote:

typedef unsigned short u16 ; //可能在您的机器上有所不同

typedef unsigned char u8; //可能在您的机器上有所不同


//假设dst在进入时初始化为零

void packBits(u8 * dst,const u16 * src)< br $> b $ b {

dst [0] | = src [0]> 1;

dst [1] | = src [0]< < 7;

dst [1] | = src [1]> 2;

dst [2] | = src [1]<< 6;

dst [2] | = src [2]> 3;

dst [3] | = src [2]<< 5;

dst [3] | = src [3]> 4;

dst [4] | = src [3]<< 4;

dst [4] | = src [4]> 5;

dst [5] | = src [4]<< 3;

dst [5] | = src [5]> 6;

dst [6] | = src [5]<< 2;

dst [6] | = src [6]> 7;

dst [7] | = src [6]<< 1;

dst [7] | = src [7]> 8;

dst [8] | = src [7];

dst [9] | = src [8]> 1;

dst [10] | = src [8]<< 7;

dst [10] | = src [9]> 2;

dst [11] | = src [9]<< 6;

}


我想用尽可能少的分号复制上面的函数。

。如果你想要解决这个难题,看看你能获得多少小小的价值,我们可以比较笔记。
typedef unsigned short u16; // may be different on your machine
typedef unsigned char u8; // may be different on your machine

// assume dst is zero initialized upon entry
void packBits( u8* dst, const u16* src )
{
dst[0] |= src[0] >1;
dst[1] |= src[0] << 7;
dst[1] |= src[1] >2;
dst[2] |= src[1] << 6;
dst[2] |= src[2] >3;
dst[3] |= src[2] << 5;
dst[3] |= src[3] >4;
dst[4] |= src[3] << 4;
dst[4] |= src[4] >5;
dst[5] |= src[4] << 3;
dst[5] |= src[5] >6;
dst[6] |= src[5] << 2;
dst[6] |= src[6] >7;
dst[7] |= src[6] << 1;
dst[7] |= src[7] >8;
dst[8] |= src[7];
dst[9] |= src[8] >1;
dst[10] |= src[8] << 7;
dst[10] |= src[9] >2;
dst[11] |= src[9] << 6;
}

I want to duplicate the above function using as few semicolons as
possible. If you want to take up the puzzle, see how small you can get
it and we can compare notes.



用* commas *替换除此函数体内最后一个分号外的所有分号

。在这里,我为你节省了19个分号(如果可以的话)。

现在,_your_笔记在哪里比较?


V

-

请在通过电子邮件回复时删除资金''A'

我没有回复最热门的回复,请不要问

Replace all but the last semicolon in the body of this function
with *commas*. Here, I saved you 19 semicolons (if I can count).
Now, where are _your_ notes to compare?

V
--
Please remove capital ''A''s when replying by e-mail
I do not respond to top-posted replies, please don''t ask


Daniel T.写道:
Daniel T. wrote:

typedef unsigned short u16; //可能在您的机器上有所不同

typedef unsigned char u8; //可能在您的机器上有所不同


//假设dst在进入时初始化为零

void packBits(u8 * dst,const u16 * src)< br $> b $ b {

dst [0] | = src [0]> 1;

dst [1] | = src [0]< < 7;
typedef unsigned short u16; // may be different on your machine
typedef unsigned char u8; // may be different on your machine

// assume dst is zero initialized upon entry
void packBits( u8* dst, const u16* src )
{
dst[0] |= src[0] >1;
dst[1] |= src[0] << 7;


>

我想使用少量分号复制上述函数

可能。如果你想接受这个谜题,看看你有多小可以获得它,我们可以比较一下音符。
>
I want to duplicate the above function using as few semicolons as
possible. If you want to take up the puzzle, see how small you can get
it and we can compare notes.



为什么?有人给分号配了吗?

如果你愿意,你可以用逗号替换每个分号除了最后一个分号

。如果这里有一些目标,除了减少分号的数量,那么在我们制作一个分号之前你必须告诉我们你真正想要做什么。聪明的回答。

Why? Did someone put a quota on semicolons?
You can replace every semicolon except for the last with a comma
if you like. If there is some goal here other than reducing the
number of semicolons, then you''ll have to tell us what you really
want to do before we can make an intelligent answer.


Ron Natalie< ro*@spamcop.netwrote:
Ron Natalie <ro*@spamcop.netwrote:

Daniel T.写道:
Daniel T. wrote:

typedef unsigned short u16; //可能在您的机器上有所不同

typedef unsigned char u8; //可能在您的机器上有所不同


//假设dst在进入时初始化为零

void packBits(u8 * dst,const u16 * src)< br $> b $ b {

dst [0] | = src [0]> 1;

dst [1] | = src [0]< < 7;
typedef unsigned short u16; // may be different on your machine
typedef unsigned char u8; // may be different on your machine

// assume dst is zero initialized upon entry
void packBits( u8* dst, const u16* src )
{
dst[0] |= src[0] >1;
dst[1] |= src[0] << 7;



我想使用尽可能少的分号复制上述函数,因为

可能。如果你想要解决这个难题,看看你能获得多少小小的价值,我们可以比较笔记。

I want to duplicate the above function using as few semicolons as
possible. If you want to take up the puzzle, see how small you can get
it and we can compare notes.



为什么?有人给分号配了吗?

如果你愿意,你可以用逗号替换每个分号除了最后一个分号

。如果这里有一些目标,除了减少分号的数量,那么在我们制作一个分号之前你必须告诉我们你真正想要做什么。聪明的回答。


Why? Did someone put a quota on semicolons?
You can replace every semicolon except for the last with a comma
if you like. If there is some goal here other than reducing the
number of semicolons, then you''ll have to tell us what you really
want to do before we can make an intelligent answer.



我正在寻找循环。我几乎可以在代码中看到一个,但是我不能很好地找到它。


-

要发送我发电子邮件,把sheltie在主题中。

I''m looking for the loop. I can almost see one in the code but I can''t
quite find it.

--
To send me email, put "sheltie" in the subject.


这篇关于请优化一下吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆