帐前卒专栏

code, software architect, articles and novels.
代码,软件架构,博客和小说

昨日上午陪着根城买衣买鞋。根城晚到到半个小时,我和西北就借此报销了中午饭。逛商店途中给西北的大脑输入多次激活码。后来竟然因饥饿产生了免疫反应。中午在港式茶餐
厅吃饭,很难吃很油腻的饭。下次绝对不去那里了,还不如旁边的KFC。出来继续闲逛。直到根城无力支付现款为止。然后回公司,search本本的价格。发现迅驰4和迅
驰2其实只有主板不同。而水货和行货只是差别在是给中国人用还是给外国人用。又发现国产和水货的价格相差无几。但是水货如果开发票还要再交5%。于是决定先看水货再看
国货。目标只是锁定在Thinkpad和联想海尔。待今天看完后再议。

饭团集合完毕后,向Sohail的住处进发。中途提前下车,是因为Annie想去先买些吃的。然后快步赶到sohail的家中是因为Lynn已经到达目的地。发现一个
饭团规律,总是Annie做决定,然后lynn再改决定。然后众人跟随着跑来跑去。

进入sohail家中的第一感觉是很暖和。第二感觉是比我寝室大。在吃饭之前还玩了几把变色龙。wei之前教会我们打法,之后输的最多。然后灯山,Shu,KC,晓勇
,芳芳陆续赶到。人数众多。灯山、lynn、annie、西北去打升级。我、根城、晓勇继续打变色龙。Shu和wei用小红帽联机打CS。KC傻乎乎的看着别人打升级
游戏。因为没有人搭理他。

然后进入吃饭时间。菜很不错。土豆泥和鸡肉块,还有色拉和水果拼盘。sohail要求我们用三个指头(拇指、食指、中指)来撕饼,然后用小块的饼来裹肉,最后在把裹好
的饼放入口中。巴基斯坦的吃饭较为烦琐,而撕饼这个动作很不适合我。于是我把整个饼裹了鸡肉块然后放入嘴里。这一吃法被KC戏称“墨西哥式”。没有想到的是,吃完饭还
有icecream吃。Shu亲自给我挖了一块冰激凌。结果我说:“就不能给我多挖几勺?”于是Shu又给我多挖了两勺。我说:“就不能给我换给品种的挖一点吗?”于
是又得到一点巧克力味道的。吃的时候看看lynn的冰激凌,又看看自己的,又看看shu,叹了口气。心想:“就不能给我多几个品种的吗?”。惹得lynn和芳芳不停的
笑。

之后开始了紧张刺激的表演接力。每人唱上一两句或者讲个笑话。等我唱完I believe I can
fly,就开始了我的拍摄活动,可惜只把wei后面的人拍摄了下来。

下面是英语听力时间,听KC和sohail用英语聊呀聊。我有点想睡觉了,于是给Lynn使了下眼色。Lynn也想走,于是提议shall we
go?之后分道扬镳。而我借助Shu的小车顺利到达公司附近某地点,下车回寝…

这个是上个星期天的事情了。感觉还是记录一下较好,毕竟自己记忆力不是很好,很容易忘却。

星期六的时候,就开始和西北,张玮商量去哪里吃饭,想到Annie在星期三说过要请大家吃饭。于是先发短信询问。接到“改到明天,几个人?”的短信,心中暗喜,于是马
上打电话募集帮众。呼应者数人。约定集结时间,以“集结好”为令。暗暗等待明天。

星期天下午2点半准时从希格玛出发,途经东华合创、荣上居,饱受风吹严寒的折磨,终于在3点左右到达目的地。Annie在家正看《武林外传》,我们几个拿着Wii抢下
电视,准备动手开战,根城趁机抢下手柄。结果…电视迟迟没有影像。重新接回闭路电视仍然无影。我们很郑重的宣布一个事实:我们成功的把电视改造成了收音机,
而且此过程不可逆。稳定了Annie很想去再买台电视的心情,我就出去接wei,结果wei在公司清空缓存区。等待近半个小时,wei清空的差不多了,可厕所差点溢出
了。

于是经历了一次严寒回到Annie住处,发现Annie挟持帮主,引着众人去买电视。无奈只得跟着,在临上汽车的瞬间,lynn打来电话,说在家门口等着。双方相持数
秒,Annie放弃回家。帮众也结束了在冰天雪地里的等待,鱼贯进入Annie家中,全部软瘫在沙发上,等待鸡汤的到来。

开饭时间,帮众吃了满满两锅,吃光Annie家的所有的东西,再次软瘫在沙发上。西北似乎没有吃饱,还在大肆咀嚼花生。

下面是扫除时间。因为PM lynn对Annie的需求没有搞清楚,结果害我拖了两遍地。由此得知,PM一定要把需求搞的明确。否则我们要多干很多事情!

1. Solve this cryptic equation, realizing of course that values for M and E
could be interchanged. No leading zeros are allowed.

WWWDOT - GOOGLE = DOTCOM

虽然找到O+L = O 或者 O - 9 -1 = O的规律,但是还是认为自己大脑再行穷举路径太多了。所以重用了自己过去的代码解决了。

//
验证函数

bool IsCorrent( int * dest)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBloc
kStart.gif) ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/
ContractedBlock.gif) … {

int wwwdot = dest[ 0 ] * ( 100000 + 10000 + 1000 ) + dest[
1 ] * 100 + dest[ 2 ] * 10 + dest[ 3 ];

int google = dest[ 4 ] * ( 100000 + 100 ) + dest[ 2 ] * (
10000 + 1000 ) + dest[ 5 ] * 10 + dest[ 6 ];

int dotcom = dest[ 1 ] * 100000 + dest[ 2 ] * ( 10000 + 10
) + dest[ 3 ] * 1000 + dest[ 7 ] * 100 + dest[ 8 ];

if (wwwdot - google == dotcom)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubB
lockStart.gif) ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicato
rs/ContractedSubBlock.gif) … {

return true ;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubB
lockEnd.gif) }

else
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubB
lockStart.gif) ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicato
rs/ContractedSubBlock.gif) … {

return false ;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubB
lockEnd.gif) }
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBloc
kEnd.gif) }

//
求子集函数

void All( int * src, int currentIndex, int len, int * dest, int
num)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBloc
kStart.gif) ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/
ContractedBlock.gif) … {

if (currentIndex == len)

return ;

dest[num ++ ] = src[currentIndex ++ ];

if (num == 9 )
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubB
lockStart.gif) ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicato
rs/ContractedSubBlock.gif) … {

Perm(dest, 0 , 8 , 9 );
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubB
lockEnd.gif) }

All(src,currentIndex,len,dest,num);

All(src,currentIndex,len,dest,num - 1 );
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBloc
kEnd.gif) }


//
求排列函数

void Perm( int * src, int current, int lesslen, int len)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBloc
kStart.gif) ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/
ContractedBlock.gif) … {

if (current == lesslen)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubB
lockStart.gif) ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicato
rs/ContractedSubBlock.gif) … {

if (IsCorrent(src))
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubB
lockStart.gif) ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicato
rs/ContractedSubBlock.gif) … {

for ( int i = 0 ; i < len; i ++ )
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubB
lockStart.gif) ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicato
rs/ContractedSubBlock.gif) … {

cout << src[i] << " " ;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubB
lockEnd.gif) }

cout << endl;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubB
lockEnd.gif) }
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubB
lockEnd.gif) }


for ( int i = current; i < len; i ++ )
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubB
lockStart.gif) ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicato
rs/ContractedSubBlock.gif) … {

swap(src[i],src[current]);

Perm(src,current + 1 ,lesslen,len);

swap(src[i],src[current]);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubB
lockEnd.gif) }

![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBloc
kEnd.gif) }

最后:

WDOTGLECM分别为7 5 8 9 1 0 6 4 3或7 5 8 9 1 0 3 4 6因为E和M可以互换,所以正解…

每K个元素逆转一次。

这段代码是从某节点开始逆转K个

ListNode* Reverse(ListNode* head,ListNode** tail,int count)
{
ListNode * pre = NULL;
ListNode * p = head;
ListNode * q = head->next;
int num = count;
if(q == NULL)
return p;
if(count <= 1)
return p;
while(p&& count–)
{
p->next = pre;
pre = p;
p = q;
if(q != NULL)
q = q->next;
else
break;
}
if(count == 0 && !p || count == -1)
{
//complete reverse
head->next = p;
*tail = head;
head = pre;
return pre;

}
else
{
//reverse back
*tail =head;
head = pre;
head=Reverse(head,tail,num-count);
return head;
}

}

//真正的逆转函数

ListNode* ReverseK(ListNode* head, int count)
{

ListNode* pre=NULL;
ListNode* p = head;
ListNode* q = head->next;
ListNode* tail = NULL;
ListNode* newHead = Reverse(head,&tail,count);

int num = count;
tail = head;
head = head->next;
ListNode* newTail = tail;
while(head)
{

head = Reverse(head,&tail,count);
newTail->next = head;
head = tail->next;
newTail = tail;
tail = tail->next;

}
return newHead;
}

//
src是源数据集合,currentIndex是在源集合里的当前下标,length为源集合的大小,dest是结果集合,num是结果集合的元素个数,初始化时,结
果集合要和源集合的个数相等.

void match( int * src, int currentIndex, int length, int * dest,
int num)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBloc
kStart.gif) ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/
ContractedBlock.gif) … {

if (currentIndex == length)

return ;


dest[num ++ ] = src[currentIndex ++ ];//采用当前元素

for ( int i = 0 ; i < num; i ++ )
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubB
lockStart.gif) ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicato
rs/ContractedSubBlock.gif) … {

cout << dest[i] << " " ;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubB
lockEnd.gif) }

cout << endl;

match(src,currentIndex,length,dest,num);//选用当前元素进行递归

match(src,currentIndex,length,dest,num - 1 );//去除当前元素再进行递归
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBloc
kEnd.gif) }

int src[] = {1,2,3};
int* dest = new int[3];打印的结果是:

1
1 2
1 2 3
1 3
2
2 3
3

所以这个算法可以求背包问,加和问题等。凡是与子集合相关的问题,全部可以用这个方法解决。

输入两个串:

string midOrder = “HDIBJEKALFMCNGO”;
string firstOrder = “ABDHIEJKCFLMGNO”;

输出一棵二叉树。

算法思想很简单,在先序中的第一个节点一定是根节点,此节点在中序中的位置可以将中序分为左右两棵子树。如:

根为A,中序分为:HDIBJEK     A   LFMCNGO,这两棵子树在使用同样的方法就生成一棵树。

//
核心算法

Node * SetTree( string & midOrder, string & firstOrder)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBloc
kStart.gif) ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/
ContractedBlock.gif) … {

if (midOrder.length() == 1 )
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubB
lockStart.gif) ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicato
rs/ContractedSubBlock.gif) … {

return new Node(midOrder);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubB
lockEnd.gif) }

string node = firstOrder.substr( 0 , 1 );

Node * n = new Node(node);

size_t i = midOrder.find(node);

size_t j = firstOrder.find(midOrder.substr(i - 1 , 1 ));

n -> left = SetTree(midOrder.substr( 0 ,i),firstOrder.substr( 1 ,i));

n -> right = SetTree(midOrder.substr(i + 1 ,midOrder.length() - i
- 1 ),firstOrder.substr(j + 1 ,firstOrder.length() - j - 1 ));

return n;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBloc
kEnd.gif) }

中序遍历和后序遍历生成树的算法类似实现。

这里因为每次递归会生成多份string,也创建了大量的额外空间,所以改进此算法,只提供下标即可:

Node* CreateTreeHelp(const char* pre_order, int p_start, int p_end, const
char* in_order, int i_start, int i_end){ if(p_end < p_start || i_end <
i_start) return NULL; char subroot_data = pre_order[p_start]; int index =
find(in_order,i_start, i_end,subroot_data); index += i_start; Node* subroot
= new Node(subroot_data); //
这里用先序的第一个节点切分中序,中序的左部节点的个数再切分先序,将中序的左部和先序的去除第一个节点,切分后的部分出入递归。 subroot->left =
CreateTreeHelp(pre_order,p_start+1,p_start+index-
i_start,in_order,i_start,index-1); // 用先序的第一个节点切分中序,中序的右部传入,将前面切分先序的第二部分传入
subroot->right = CreateTreeHelp(pre_order,p_start+index-
i_start+1,p_end,in_order,index+1,i_end); return subroot; }

如果思考不清晰,这部分调试起来还是比较困难。需要打印每次递归的信息,最后先使用小数据量,然后打印出来,而不要用gdb调试。源程序是这样打印的:

TreeNode* CreateTreeHelp(const char* pre_order, int p_start, int p_end,
const char* in_order, int i_start, int i_end, int tabs){ for(int i = 0; i <
tabs; i++){ cout << “.”; } cout <<endl; if(p_end < p_start || i_end < i_start)
return NULL; char subroot_data = pre_order[p_start]; int index =
find(in_order,i_start, i_end,subroot_data); index += i_start; TreeNode*
subroot = new TreeNode(subroot_data); const char * tmp =
pre_order+p_start; while(*tmp != pre_order[p_end+1]){ cout << *tmp<<" “;
tmp++; } cout << endl; tmp = in_order+i_start; while(*tmp !=
in_order[i_end+1]){ cout << *tmp<<” “; tmp++; } cout << endl; cout <<
“index:”<<index<<endl; cout << “p_start:”<<p_start<<” p_end:“<<p_end<<”
i_start:“<<i_start<<” i_end:"<<i_end<<endl; subroot->left =
CreateTreeHelp(pre_order,p_start+1,p_start+index-
i_start,in_order,i_start,index-1,tabs+2); subroot->right =
CreateTreeHelp(pre_order,p_start+index-
i_start+1,p_end,in_order,index+1,i_end,tabs+2); return subroot; }

另外贴上其中的find函数,这里的count其实是找对于start来说的相对位置(师兄说下面这段代码写的很烂,但是烂的凑在一起,竟然没有错,这让我想到了独孤
九剑):

int find(const char* str, int start, int end,const char& c){ int count = -1;
str = str+start; int len = end-start; while(‘/0’ != *str && count <=len){
count++; if(c == *str) return count; str++; } return -1; }

这是为什么呢?因为里面使用到多个判断标准…所以改为:

int find(const char* str, int start, int end,const char& c){ int count = -1;
str = str+start; const char* str_end = str+end+1; while(*str_end != *str){
count++; if(c == *str++) return count; } return -1; }

** 龟虽寿 **

曹操

神龟虽寿,犹有竟时。
腾蛇乘雾,终为土灰。
老骥伏枥,志在千里;
烈士暮年,壮心不已。
盈缩之期,不但在天;
养怡之福,可得永年。
幸甚至哉,歌以咏志。

在微软结识了很多朋友,现在在做polit,没有什么程序要写。所以每天吃吃喝喝忙的不亦乐乎。加入了饭团,还有了个老大。于是近几个星期整天跟在老大后面混口饭吃,
也准备学Wei和Shawn来个10元包月套餐。也可以跟在老大去去健身房。反正最近也要把健身卡用完。
想想再过一个月就要离开他们,还真是恋恋不舍。准备为饭团中的各位做传,以示缅怀。

瑞军老大:饭团的组建者之一。在外漂泊了多年,现归顺微软。在他那里了解到更多的人世沧桑、世态炎凉。因为年龄最大,所以阅历很广。不过依然是一个80后的人。现在是
Super Dev。同时也是非常有创意,非常幽默的一个人。他的MSN的头像就是Super dog.

Lynn:饭团中最活跃的一个人。因为出身就是PM,所以活跃也是非常应该的事情。前几个星期见到我后的口头蝉:“本来多乖的小孩,被瑞军带了几天,就…”。
最近的口头蝉:“你太勤奋了,比你老大都勤奋。你怎么能比你老大还勤奋呢?”PM的职责就是增加团队凝聚力,活跃团队气氛。所以Lynn是一个非常出色的PM。至少我
认为是这样:)瑞军肯定不这样想,因为Lynn把太多工作都给他做了。Lynn对瑞军的口头蝉:“这是我们团队的dev,交给他什么他都能做出来。”于是啥东西都让他
做了。写在这里发现对Lynn描述的篇幅远远的超过了瑞军。因为她是我另一个老大。一个是有文化的老大,一个是“没文化”的老大。最搞笑的事就是某天晚上,我和瑞军一
起“欣赏“Lynn的人脸识别论文。

Wei: 饭团里又一个Strong Dev.说他strong,是因为他非常的爱说:“You are so strong!”.对付他的两句话:“you are
so handsome!” or " you are stronger than me!".他自己没事写写windows
mobile的小程序,然后每次吃饭都要展示一下。Cool Feature.

Shawn:“人品极差”,他这样形容自己。近几次饭团聚会,提要要10月包月的人。现在主管Symbian平台的程序测试。非常喜欢讲笑话的一个人。每次讲笑话,头
句一定是:“小明…”。我们强烈要求换个主人公。于是某天,主人公变为了我。

西北:很有可能会成为我师兄的一个人。如果只有一句来描述他,这实在是不给他面子,加上这一句,正好是俩句话。…西北看了会疯的…西北很生气,后
果???

根城:现在FTE中最小的一个。不过套用Lynn的话,我永远都比他小。所以因为我的存在,我就是整个饭团中最小的。所以Lynn说,我是他们所有人的小弟。他一定是
晚上留下来在b1吃饭的。所以每天晚上还都有个伴去吃饭。

Annie:测试组的大姐。一旦测试有啥问题,他们一定说,把你大姐找来。Annie写文档的功底是非常非常强的。而且她曾经pass了IBM等多家大公司的面试。最
后止步在微软。所以一有空,她就会到我们的做题沙龙里凑热闹,然后她就会变成热闹的中心了。

Cloud:中午只吃玉米减肥的人。结果就是越减越肥。也是我们当中打foosball最好的前锋。顺便一提:Annie是最好的后卫,我可能只能打过瑞军。不过我已
经极大的满足了。我偶然赢了Annie一次,还兴奋了半天。Cloud除了foosball之外,还是个题库。所以做题沙龙老是先让他出几个题。

大家在饭团里吃的都非常的开心。吃饭的时候大家不停的笑就对了,最好吃的不笑,否则要喷饭的!


int StrCmp( const char * des, const char * src)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBloc
kStart.gif) ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/
ContractedBlock.gif) … {

int c;

if (des == NULL || src == NULL)

throw " NULL point " ;

int len1 = strlen(des);

int len2 = strlen(src);

if (len1 != len2)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubB
lockStart.gif) ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicato
rs/ContractedSubBlock.gif) … {

return len1 - len2;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubB
lockEnd.gif) }

while ( * des != ’ /0 ’ )
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubB
lockStart.gif) ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicato
rs/ContractedSubBlock.gif) … {

if ((c = ( * des ++ - * src ++ )) != 0 )
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubB
lockStart.gif) ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicato
rs/ContractedSubBlock.gif) … {

return c;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubB
lockEnd.gif) }
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubB
lockEnd.gif) }

return c;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBloc
kEnd.gif) }

测试用例:

1.字符串为AscII串,并且src和des不为空,测试中以src和des长度分类

2.字符串为高AscII串…

3.字符串为DBCS串

4.字符串中包含DBCS和ASCII

5.src或者des为NULL

6.src和des为""


char * ItoA( int value, char * dest, int r)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBloc
kStart.gif) ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/
ContractedBlock.gif) … {

if (value < 0 && r != 10 )

throw " Exception " ;

int flag = 1 ;

if (value < 0 )
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubB
lockStart.gif) ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicato
rs/ContractedSubBlock.gif) … {

flag = - 1 ;

value = - value;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubB
lockEnd.gif) }

char * map = " 0123456789abcdef " ;

char * reDest = dest;

do
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubB
lockStart.gif) ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicato
rs/ContractedSubBlock.gif) … {

  • dest ++ = map[value % r];
    ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubB
    lockEnd.gif) } while (value /= r);

    if (flag == - 1 )
    ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubB
    lockStart.gif) ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicato
    rs/ContractedSubBlock.gif) … {
  • dest ++ = ’ - ’ ;
    ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubB
    lockEnd.gif) }
  • dest = ’ /0 ’ ;

    int len = strlen(reDest);

    for ( int i = 0 , j = len - 1 ; i < j; i ++ , j -- )
    ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubB
    lockStart.gif) ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicato
    rs/ContractedSubBlock.gif) … {

    swap(reDest[i],reDest[j]);
    ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubB
    lockEnd.gif) }

    return reDest;
    ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBloc
    kEnd.gif) }

测试用例:

1.10进制 正数,负数,0

2.16进制 正数

3.0进制 (Crash)

4.进制为负

5.负16进制

6.传入的char数组长度小于生成的数字长度

7.20进制

8.dest为NULL

9.value 为 2^31-1 或 -2^31

0%