大家都一直强调规范编码。可是这个世界上有个大师们娱乐的竞赛——国际乱码大赛。

能写出来的都是对语言深入了解的master。我从没想自己也能“恶搞”C,一直都是老老实实编码。就在前几天看了一篇帖子。

感觉把非常规范的代码变成乱码。非常有意思。于是决定动手试一试。

我不得不说。。。我以为看起来还简单的东西。搞了我一天,我去。

。。各种bug。。。

只是也有非常大的收获。我没想到“把代码写乱”也能给我代码收获。

。。我想。这的确非常有意思。This blog will memory my work and process with the interesting skill.

感觉hello world级别的改不出什么东西来,不够“炫酷”。挑了几个好玩的代码。于是选中了以下这块实验田:

/*
1
2 3
4 5 6
7 8 9 10 实现输出三角形数阵 */
#include <stdio.h>
int main ()
{
int row=0,rank=0,num=0,blank=0;//row行,rank列变量,blank变量控制打印空格
int n[10];
for(num=1;num<=10;num++)//给数组赋初值,通过改动这一步得到你想要的数据
{
n[num-1]=num;//通过改动这一步得到你想要的数据。比如2*num-1
} num=0; for(row=1;row<=4;row++)//输出
{
for(blank=1;blank<=5-row;blank++)
printf(" "); for(rank=1;rank<=row;rank++)
{
printf("%d ",n[num]);
num++;
if(rank==row)
printf("\n");
}
}
return 0;
}

对于学过C的老手来说,看懂这个全然不是问题

新手可能有点别扭。只是我还是比較喜欢这家伙,打印了一个三角形数字阵

jasonleaster@ubuntu:~/Desktop$ ./a.out

    1  

   2  3  

  4  5  6  

 7  8  9  10

代码变乱第一步

将for循环改成while循环

void triangle(void)
{
int row = 0,rank = 0,num=0,blank=0;//row行,rank列变量,blank变量控制打印
空格 int n[10]; num = 1; while(num<=10)//给数组赋初值,通过改动这一步得到你想要的数据
{
n[num-1]=num;//通过改动这一步得到你想要的数据,比如2*num-1
num++;
} num=0;
row = 1;
while(row <= 4)//输出
{
blank = 1;
while(blank <= 5-row)
{
printf(" ");
blank++;
} rank = 1;
while(rank<=row;)
{
printf("%d ",n[num]);
num++;
if(rank==row)
printf("\n"); rank++;
}
row++
} return ;
}

这样恶搞的全然还没有深度。

。可是。是个非常好的铺垫。

恶搞代码步骤二,把while循环变递归

通过这个练习能够加强自己的逻辑思维,对于代码的逻辑理解将会非常仔细。。。后面还会更仔细。

。。

。。

/*
1
2 3
4 5 6
7 8 9 10 实现输出三角形数阵 */
#include <stdio.h> int n[10];//Attention. I change the "n" array into a global array static int location = 0; int triangle(int num,int row,int rank,int blank); int main()
{
triangle(1,1,1,1); return 0;
} int triangle(int num,int row,int rank,int blank)
{ //-------------the first recursion block------------------------------
if(num<=10) {
triangle(num+1,0,0,0);
n[num-1] = num; if(num != 1)
{
return 0;
}
}
else if(num == 11)
{
return 0;
}
//------------------------------------------------------------------ //-------------------the fourth recursion block-------------
if(row <= 4)//输出
{
//--------------the second recursion block---------
if(blank <= 5-row)
{
printf(" ");
triangle(12,row,rank,blank+1);//num == 12 pass the first recursion block
if(blank != 1)
{
return 0;
}
}
else if(blank != 100)
{
return 0;//end the recursion
} //---------------------------------------------- //-----------the third recursion block------------ if(rank <= row)
{
printf("%d ",n[location]);
location++; if(rank==row)
printf("\n"); triangle(12,row,rank+1,100);//pass the first and the second recursion
if(rank != 1)
{
return 0;
}
}
else
{
return 0;
}
//--------------------------------------------- triangle(12,row+1,rank,blank);// pass the first recursion } return 0;
}

基本的要领就是通过return 适时的解释当前递归。

(我的这样的策略还不是非常好。事实上能够改变代码的逻辑。消除return 让被调用函数自己主动的在适当的时候挂掉。。而不是通过return 主动杀死。。。

正由于这样,我后面花了非常多时间改代码的逻辑结构)

昨晚凌晨3点半的时候。放弃了,今天晚上8点多的时候调出来了。。

这里去掉了return 原因嘛。就是为了 条件操作符做准备,把代码变的更难看

要知道

推断语句? return :0;

这类的语句是违法的,return 不是个expression,所以不能用在 选择操作符的右边。。。昨晚就是由于这个放弃继续恶搞的。改结构非常坑爹的说。非常锻炼逻辑的说。

//简直就是艰辛!

~

/*
1
2 3
4 5 6
7 8 9 10 实现输出三角形数阵 */
#include <stdio.h> int n[10];//Attention. I change the "n" array into a global array static int location = 0; static int dead = 0; static int first_r = 1; static int second_r = 0; static int third_r = 0; static int fourth_r = 0; void triangle(int num,int row,int rank,int blank); int main()
{
triangle(1,1,1,1); return 0;
} void triangle(int num,int row,int rank,int blank)
{ dead = 0;
//-------------the first recursion block------------------------------
if (num<=10)
{
if(first_r !=0 && second_r != 1 && third_r != 1 && fourth_r != 1)
{
triangle(num+1,0,0,0);
n[num-1] = num;
first_r = 0;
second_r = 1;//进行第二个递归
third_r = 0;
fourth_r = 0;
} if(num == 1)
{
if(row <= 4)
{
//--------------the second recursion block---------
if((blank <= 5-row) && (first_r != 1&& second_r != 0 && third_r != 1 && fourth_r != 1))
{
printf(" ");
if(first_r != 1&& second_r != 0 && third_r != 1 && fourth_r != 1)
{
triangle(1,row,rank,blank+1);
first_r = 0;
second_r =0;
third_r = 1;//进行第三个递归
fourth_r = 0; if(blank != 1)
{
dead = 1;
}
else
{
dead = 0;
}
}
}
else
{
dead = 1;
} if(blank == 1)
{
if(rank <= row)
{
printf("%d ",n[location]);
location++; if(rank==row)
{
printf("\n");
dead = 0;
} if(row != rank && (first_r != 1&& second_r != 1 && third_r != 0 && fourth_r != 1))
{
triangle(1,row,rank+1,1);//pass the first and the second recursion
first_r = 0;
second_r = 0;
third_r = 0;
fourth_r = 1;
dead = 1;
}
}
} if(dead == 0)
{
first_r = 1;
second_r= 0;
third_r = 0;
fourth_r= 0;
triangle(1,row+1,1,1);// pass the first recursion
}
}
}
}
}

我预计没人会去分析上面的代码了。各种递归,各种条件限制。

Now,it's time to show the shit!

以下那坨东西是能够执行的。

亲測。。。

/*
1
2 3
4 5 6
7 8 9 10 实现输出三角形数阵 */
#include <stdio.h> int n[10];//Attention. I change the "n" array into a global array static int location = 0; static int dead = 0; static int first_r = 1; static int second_r = 0; static int third_r = 0; static int fourth_r = 0; void triangle(int num,int row,int rank,int blank); int main()
{
triangle(1,1,1,1); return 0;
} void triangle(int num,int row,int rank,int blank)
{ dead = 0;
(num<=10) ? (((first_r !=0 && second_r != 1 && third_r != 1 && fourth_r != 1) ? \
( triangle(num+1,0,0,0),n[num-1] = num,first_r = 0,second_r = 1,third_r = 0,fourth_r = 0):0),\
((num == 1) ? ((row <= 4) ? (( ((blank <= 5-row) &&\
(first_r != 1&& second_r != 0 && third_r != 1 && fourth_r != 1)) ? \
( printf(" "),(first_r != 1&& second_r != 0 && third_r != 1 && fourth_r != 1) ?\
(triangle(1,row,rank,blank+1),first_r = 0,second_r =0,third_r = 1,fourth_r = 0,((blank != 1) ? \
(dead = 1) :(dead = 0))) : 0) : (dead = 1) ),((blank == 1) ? ((rank <= row) ?\
((printf("%d ",n[location]),location++),((rank==row) ? ( printf("\n"),dead = 0) : 0),\
((row != rank && (first_r != 1&& second_r != 1 && third_r != 0 && fourth_r != 1)) ?\
( triangle(1,row,rank+1,1),first_r = 0,second_r = 0,third_r = 0,fourth_r = 1,dead = 1) : 0)) : 0 ) : 0),\
((dead == 0) ? (first_r = 1,second_r= 0,third_r = 0,fourth_r= 0,triangle(1,row+1,1,1)) : 0) ) : 0 ) : 0 )):0; }

liuzjian@ubuntu:~$ ./a.out

    1  

   2  3  

  4  5  6  

 7  8  9  10

上面那坨翔可能一般看来好像无解。事实上还是有解的。逆向仅仅要依据括号的匹配规则是能够把代码变规范的。

仅仅是。。。我预计这是个非常蛋疼的工作。。

怎么把代码变的更操蛋?

第三步,糟糕的变量名

#include <stdio.h>

int n[10];
static int _ = 0; static int __ = 0; static int ___ = 1; static int ____ = 0; static int ______ = 0; static int _______ = 0; void ____________(int ________,int _________,int __________,int ___________); int main()
{
____________(1,1,1,1); return 0;
} void ____________(int ________,int _________,int __________,int ___________)
{ __ = 0; (________<=10) ? (((___ !=0 && ____ != 1 && ______ != 1 && _______ != 1) ? \
( ____________(________+1,0,0,0),n[________-1] = ________,___ = 0,____ = 1,______ = 0,_______ = 0):0),\
((________ == 1) ? ((_________ <= 4) ? (( ((___________ <= 5-_________) &&\
(___ != 1&& ____ != 0 && ______ != 1 && _______ != 1)) ? \
( printf(" "),(___ != 1&& ____ != 0 && ______ != 1 && _______ != 1) ? \
(____________(1,_________,__________,___________+1),___ = 0,____ =0,______ = 1,_______ = 0,((___________ != 1) ?\
(__ = 1) :(__ = 0))) : 0) : (__ = 1) ),((___________ == 1) ? ((__________ <= _________) ?\
((printf("%d ",n[_]),_++),((__________==_________) ? ( printf("\n"),__ = 0) : 0),\
((_________ != __________ && (___ != 1&& ____ != 1 && ______ != 0 && _______ != 1)) ?\
( ____________(1,_________,__________+1,1),___ = 0,____ = 0,______ = 0,_______ = 1,__ = 1) : 0)) : 0 ) : 0),\
((__ == 0) ? (___ = 1,____= 0,______ = 0,_______= 0,____________(1,_________+1,1,1)) : 0) ) : 0 ) : 0 )):0;}

jasonleaster@ubuntu:~/Desktop$ ./a.out

    1  

   2  3  

  4  5  6  

 7  8  9  10 



我相信上面这个东东能够把人送进疯人院,可是。。。

它确实能够执行。

对于那些变量名乱用的programmer不要有包容心。切记。

通过"恶搞",事实上能更深的理解语言本身,可以更好的锻炼逻辑分析能力。

学会控制自己的逻辑,不要写自己也不知道的东西。

规范编码非常重要。

事实上恶搞过程中,我领悟最深刻的是两点

1。

代码逻辑的重构

2。普通循环和递归之间的转换

这两点是我最开心的领悟

最新文章

  1. 深入理解js的变量提升和函数提升
  2. Hibernate QBC运算符
  3. Socket实现仿QQ聊天(可部署于广域网)附源码(2)-服务器搭建
  4. Sublime Text 2 安装与使用SFTP插件
  5. IP处理函数inet_aton()和inet_ntoa(),inet_pton,inet_ntop
  6. js 当前系统时间
  7. Java性能漫谈-数组复制之System.arraycopy
  8. OpenGL路(四)自制的图形功能(立方体、汽缸、圆锥)
  9. hdu 3507 Print Article(斜率优化DP)
  10. 数字三角形-poj
  11. 异常-----Can&#39;t convert the date to string, because it is not known which parts of the date variable are in use. Use ?date, ?time or ?datetime built-in, or ?string.\u003Cformat&gt; or ?string(format) built-
  12. 小程序应用的Python服务器部署高配,依然是腾讯云秒杀阿里云!
  13. Vue route部分简单高级用法
  14. c/c++ 标准库 map set 大锅炖
  15. 潭州课堂25班:Ph201805201 django 项目 第三十课 linux 系统迁移 (课堂笔记)
  16. hibernate多对多关系
  17. C# 自定义承载控件
  18. UINavigationController 返回到各级目录
  19. Consul Session
  20. C#中哈希表(HashTable)的用法详解

热门文章

  1. 009 CSS选择器
  2. (4)zabbix监控第一台服务器
  3. docker系列之安装配置
  4. 如何用纯 CSS 创作一个均衡器 loader 动画
  5. 正负无穷float(&#39;inf&#39;)的一些用法
  6. luogu3698 [CQOI2017]小Q的棋盘
  7. NYOJ 293 Sticks
  8. Flutter 发布APK时进行代码/资源混淆的坑
  9. 九度oj 题目1096:日期差值
  10. ajax 原生 post