社区讨论
本机AC,提交WA
UVA227谜题 Puzzle参与者 4已保存回复 5
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 5 条
- 当前快照
- 1 份
- 快照标识符
- @mi7pbm51
- 此快照首次捕获于
- 2025/11/21 01:24 4 个月前
- 此快照最后确认于
- 2025/11/21 01:24 4 个月前
CPP
//#include <iostream>
#include <stdio.h>
using namespace std;
char str[7][7];
int main()
{
int i,j,kase=1;
//ios::sync_with_stdio(false);
while(1)
{
int x,y;
char operation='\0';
//if (kase>1) getchar();
//freopen("UVA227.in","r",stdin);
//freopen("UVA227.out","w",stdout);
str[1][1]=getchar();
if (str[1][1]=='Z') return 0;
if (kase!=1) printf("\n");
for(i=1;i<=5;i++)
{
for(j=1;j<=5;j++)
{
if(!(i==1&&j==1))
{
scanf("%c",&str[i][j]);
}
if(str[i][j]=='\n'||str[i][j]=='\r')
{
str[i][j]=' ';
}
//printf("%c",str[i][j]);
//printf("\n");
if(str[i][j]=='Z')
{
return 0;
}
if(str[i][j]==' ')
{
x=i;
y=j;
}
}
fflush(stdin);
}
int flag=1;
while(operation!='0')
{
scanf("%c",&operation);
if(operation=='\n'||operation=='\r')
{
continue;
}
//printf("%c",operation);
if(flag)
{
switch(operation)
{
case 'A':
{
if(str[x-1][y]=='\0')
{
flag=0;
}
else
{
char t;
t=str[x-1][y];
str[x-1][y]=str[x][y];
str[x][y]=t;
x--;
}
//printf("A\n");
break;
}
case 'B':
{
if(str[x+1][y]=='\0')
{
flag=0;
}
else
{
char t;
t=str[x+1][y];
str[x+1][y]=str[x][y];
str[x][y]=t;
x++;
}
//printf("B\n");
break;
}
case 'L':
{
if(str[x][y-1]=='\0')
{
flag=0;
}
else
{
char t;
t=str[x][y-1];
str[x][y-1]=str[x][y];
str[x][y]=t;
y--;
}
//printf("L\n");
break;
}
case 'R':
{
if(str[x][y+1]=='\0')
{
flag=0;
}
else
{
char t;
t=str[x][y+1];
str[x][y+1]=str[x][y];
str[x][y]=t;
y++;
}
//printf("R\n");
break;
}
case '\n':break;
case '\r':break;
case '0':break;
default:flag=0;
}
}
}
fflush(stdin);
printf("Puzzle #%d:\n",kase++);
if(flag)
{
for(i=1;i<=5;i++)
{
for(j=1;j<=5;j++)
{
if(j==1)
{
printf("%c",str[i][j]);
}
else
{
printf(" %c",str[i][j]);
}
}
printf("\n");
}
}
else
{
printf("This puzzle has no final configuration.\n");
}
}
return 0;
}
回复
共 5 条回复,欢迎继续交流。
正在加载回复...