uva227求教。

SnatchyAsp 2016-03-06 01:36:50
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int act0=0,puzzle0=0,i,j,num=0,x,y,outrange=0,stop=0;
char act[1000],puzzle[5][5];
while(puzzle0==0)
{
if (act0==0)
{
gets(act);
if (act[0]=='Z')
{
puzzle0=1;
break;
}
else
{
for(i=0;i<5;i++)
{
puzzle[0][i]=act[i];
}
for (i=1;i<5;i++)
{
gets(puzzle[i]);
}
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(puzzle[i][j]==' ')
{
x=i;
y=j;
}

}
}
}
act0=1;
}
if (act0==1 && outrange==0)
{
gets(act);

for(i=0;i<strlen(act);i++)
{
if(act[i]=='L')
{
if (y-1<0)
{

if (act[strlen(act)-1]=='0')
stop=1;

outrange=1;
break;

}
else
{
puzzle[x][y]=puzzle[x][y-1];
puzzle[x][y-1]=' ';
y=y-1;
}


}
else if(act[i]=='R')
{
if (4<y+1)
{
if (act[strlen(act)-1]=='0')
stop=1;

outrange=1;
break;

}
else
{
puzzle[x][y]=puzzle[x][y+1];
puzzle[x][y+1]=' ';
y=y+1;
}


}
else if(act[i]=='A')
{
if (x-1<0)
{

if (act[strlen(act)-1]=='0')
stop=1;

outrange=1;
break;
}
else
{
puzzle[x][y]=puzzle[x-1][y];
puzzle[x-1][y]=' ';
x=x-1;
}


}
else if(act[i]=='B')
{
if (4<x+1)
{

if (act[strlen(act)-1]=='0')
stop=1;

outrange=1;
break;


}
else
{
puzzle[x][y]=puzzle[x+1][y];
puzzle[x+1][y]=' ';
x=x+1;
}
}
else if(act[i]=='0')
{
num++;
printf("\nPuzzle #%d:\n", num);
for (i=0;i<5;i++)
{
for (j=0;j<4;j++)
{
printf("%c ", puzzle[i][j]);
}
printf("%c\n", puzzle[i][4]);
}
act0=0;

}
}
}
if (act0==1 && outrange==1)
{
num++;
printf("\nPuzzle #%d:\n", num);
printf("This puzzle has no final configuration.\n");
while(stop==0)
{
char act[1000];
gets(act);
if (act[strlen(act)-1]=='0')
{

stop=1;
}
}
stop=0;
outrange=0;
act0=0;
}
}
return 0;
}

为什么有的数据会无限循环。。。
比如说
TRGSJ
XDOKI
M VLN
WPABE
UQHCF
ARRBBL0求大神
...全文
136 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2016-03-08
  • 打赏
  • 举报
回复
代码功能归根结底不是别人帮自己看或讲解或注释出来的;而是被自己静下心来花足够长的时间和精力亲自动手单步或设断点或对执行到某步获得的中间结果显示或写到日志文件中一步一步分析出来的。 提醒:再牛×的老师也无法代替学生自己领悟和上厕所! 单步调试和设断点调试(VS IDE中编译连接通过以后,按F10或F11键单步执行,按Shift+F11退出当前函数;在某行按F9设断点后按F5执行停在该断点处。)是程序员必须掌握的技能之一。
paschen 2016-03-06
  • 打赏
  • 举报
回复
建议自己单步调试程序,看程序一步步怎么执行的,而不要看着代码空想
SnatchyAsp 2016-03-06
  • 打赏
  • 举报
回复
刚学没多久,希望能够指点

69,368

社区成员

发帖
与我相关
我的任务
社区描述
C语言相关问题讨论
社区管理员
  • C语言
  • 花神庙码农
  • 架构师李肯
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧