1995年第十二届IOCCC获奖作品,由葡萄牙的Carlos Duarte先生所编写。评委们评论说:
This could be used as the basis of an a-maze-ing screen exerciser.
以下是作者本人对程序的简要介绍:
A program that generates a maze, and then solves it, all this being seen by the user. Some highlights of obfuscation are: 3 steps functions in one - main(), several recursive calls with conditional actions, and just one (big and ugly) statement to solve the maze.
你可以从www.ioccc.org上找到这个名为cdua.c的源程序,也可以参考下面的代码。由于这里上传的代码会被重新格式化,强烈建议你去下载原来的程序。
/*************************************************************/
#define r return
char*u0="
",*u3="Walking... ",*u4="Finished. ",*u5="Going back..\
. ",*o="\033[23;1HDone!!\n",*x="\033[2J",*y="\033[1;1H",*z="\033[%d;%\
dH%c",*w="\033[1;1H%s",*v="\033[%d;%dH%c\033[%d;%dH%c\033[%d;%dH%c",b[1841
];int c,d,e,f,g;typedef int(*h)();h i,j,k,l,m,n;int printf(),srand(),rand(
),time(),getchar();int main(int a){i=printf,j=srand,k=rand,l=time,m=getchar,
n=main;if(!c)for(j(l(0)),g=a=1000,--d;++d<1840;b[c=d]=" #\n"[d%80==79?2:d/80
&&d%80&&d/80-22&&d%80-78]);if(!(c-1839))++c,i("%s%s%s",x,y,b);k:if(!(c-1840)
&&(b[a+2]+b[a-2]+b[a+160]+b[a-160]-4*' ')){while(b[a+(f=(e=k()%4)?e-1?e-2?-1
:1:-80:80)*2]!='#');b[a]=b[a+f]=b[f+a+f]=' ';i(v,a/80+1,1+a%80,' ',(a+f)/80+
1,1+(a+f)%80,' ',(f+a+f)/80+1,1+(f+a+f)%80,' ');n(f+a+f);goto k;}else if(!(g
-a))c=1,a=162,i(w,u0),m();if(c-1){}else r b[a]!=' '?(i(w,b[a]=='.'?u1:u2),0)
:(b[a]='.',i(w,u3),i(z,a/80+1,1+a%80,'.'),a==1676?(i(w,u4),i(o),1):n(a+1)||n
(a+80)||n(a-80)||n(a-1)?1:(b[a]=' ',i(w,u5),i(z,a/80+1,1+a%80,' '),0));r 0;}
我曾运行过这个程序,非常的有意思,当然,尝试理解这样的代码更有趣。
#include
const int m=4,n=4;
int maze[m+2][n+2];//定义迷宫数组
int mark[m+2][n+2];//定义保存访问标记的数组
int move[4][2]={{0,1},{1,0},{0,-1},{-1,0}};//0,1,2,3代表东,西,南,北
int SeekPath(int x,int y)
{
int i; //代表从当前位置移到下一位置的方向
int g,h; //下一位置坐标
if((x==m)&&(y==m))return 1;//到达出口点返回ture结束递归
for(i=0;i<4;i++)
{
g=x+move[i][0];h=y+move[i][1];//求下一位置坐标
if((maze[g][h]==0)&&(mark[g][h]==0))//若下一位置未被访问,则从该位置开始寻找
{
mark[g][h]=1; //已访问结点做好标记
if(SeekPath(g,h)){
cout<<"("<
}
}
}
cout<<"此迷宫无路径"<
}
void main()
{
int i,j;int q;
while(q!=0)
{
cout<<"请输入6行,6列迷宫数据(0表示通路1表示不通!迷宫四周的值全为1!):"<
for(i=0;i
mark[1][1]=1; //置入口标记为1
if(SeekPath(1,1)) //递归求路径
cout<<"("<<1<<","<<1<<")"<
}
}
树的遍历