uva 227 - Puzzle试了好多数据还是不知道哪里错了,老是WA

AC_Arthur 2014-12-09 08:18:32
#include<stdio.h>
#include<string.h>
int main()
{
int i,j;
char a[12][12];
int maxn;
maxn=0;
while(gets(a[0]))
{
if(strcmp(a[0], "Z")==0)
return 0;
for(i=1;i<5;i++)
{
gets(a[i]);
}
int x,y;
x=10;y=10;
for(i=0;i<5;i++)
{
for (j=0;j<5;j++)
{
if(a[i][j]==' ')
{
x=i;y=j;
}
}
}
int tot;
tot=0;
int c;
while((c=getchar())!='0')
{
switch(c)
{
case 'A':if(x>0){a[x][y]=a[x-1][y];a[x-1][y]=' ';x-=1;} else {tot=1;}break;

case 'B':if(x<4){a[x][y]=a[x+1][y];a[x+1][y]=' ';x+=1;} else {tot=1;}break;

case 'L':if(y>0){a[x][y]=a[x][y-1];a[x][y-1]=' ';y-=1;} else {tot=1;}break;

case 'R':if(y<4){a[x][y]=a[x][y+1];a[x][y+1]=' ';y+=1;} else {tot=1;}break;
}
}

maxn++;
printf("Puzzle #%d:\n",maxn);
if(tot==1)
printf("This puzzle has no final configuration.\n\n");
else
{
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(j==4)
printf("%c",a[i][j]);
else
printf("%c ",a[i][j]);
}

printf("\n");
if(i==4)
printf("\n");
}
}
gets(a[0]);
}
return 0;
}
求大神指点。。。
...全文
402 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
windrises 2015-02-14
  • 打赏
  • 举报
回复
引用 4 楼 biancheng101 的回复:
楼主,你好。我也遇到了跟你一样的情况。你说的把多出的空行删掉,我不知道该如何操作?
你可以在循环的开头输出回车 int cnt=0; while(gets(a[1]+1)&&a[1][1]!='Z') { ++cnt; if(cnt>1) printf("\n"); ------------------------------------------------------
biancheng101 2015-02-10
  • 打赏
  • 举报
回复
楼主,你好。我也遇到了跟你一样的情况。你说的把多出的空行删掉,我不知道该如何操作?
AC_Arthur 2015-02-09
  • 打赏
  • 举报
回复
引用 2 楼 weizhuwyzc000 的回复:
我找到bug了。。。。题目要求各组数据之间输出一个空行。。。而这意味着最后一组数据后不能有空行,多输出了空行会得WA
唉。。还得靠自己啊~~
AC_Arthur 2015-02-09
  • 打赏
  • 举报
回复
我找到bug了。。。。题目要求各组数据之间输出一个空行。。。而这意味着最后一组数据后不能有空行,多输出了空行会得WA

69,371

社区成员

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

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