首页 新闻 搜索 专区 学院

有做过UVa 227 Puzzle的吗?求指出代码的错误

0
悬赏园豆:30 [待解决问题]

include<stdio.h>

include<string.h>

char a[7][7] = { 0 }, count = 0, gg = 0, x;
int main(void)
{
while (1)
{
int x0 = 0, y0 = 0, jd = 0;
for (int i = 1; i <= 5; i++)
{
for (int j = 1; j <= 5; j++)
{
scanf("%c", &a[i][j]);
if (a[1][1] == 'Z') return 0;
if (a[i][j] == ' ') { x0 = i; y0 = j; }
}
getchar();
}
while ((x=getchar())!='0')
{
if (x == 'A') { a[x0][y0] = a[x0 - 1][y0]; a[x0 - 1][y0] = ' '; x0--; }
if (x == 'B') { a[x0][y0] = a[x0 + 1][y0]; a[x0 + 1][y0] = ' '; x0++; }
if (x == 'L') { a[x0][y0] = a[x0][y0 - 1]; a[x0][y0 - 1] = ' '; y0--; }
if (x == 'R') { a[x0][y0] = a[x0][y0 + 1]; a[x0][y0 + 1] = ' '; y0++; }
if (x0 <= 0 || y0 <= 0 || x0 > 5 || y0 > 5)
jd = 1;
}
getchar();
if (gg)printf("\n");
else gg = 1;
if (jd)
printf("Puzzle #%d:\nThis puzzle has no final configuration.\n", ++count);
else
{
printf("Puzzle #%d:\n", ++count);
for (int i = 1; i <= 5; i++)
{
for (int j = 1; j <= 5; j++)
{
if (j != 1)printf(" ");
printf("%c", a[i][j]);
}
printf("\n");
}
}
}
return 0;
}

TKwang的主页 TKwang | 初学一级 | 园豆:174
提问于:2020-01-23 23:16
< >
分享
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册