Puzzle UVA - 227
程序员文章站
2022-07-13 17:13:15
...
https://cn.vjudge.net/contest/239026#problem/A
#include <stdio.h>
#include <ctype.h>
#include <string.h>
#define M 10
int main(int argc, char *argv[])
{
int i,j,k,n=1,x,y,bz,l;
char t,c[M][M];
while(gets(c[0]))
{
if(c[0][0]=='Z')
return 0;
bz=0;
for(i=1;i<5;i++)
{
gets(c[i]);
l=strlen(c[i]);
if(l<5)
c[i][4]=' ';
}
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
{
if(c[i][j]==' ')
{
x=i;
y=j;
}
}
}
char ch;
while((ch=getchar())!='0')
{
switch(ch)
{
case 'A':if(isalpha(c[x-1][y])){t=c[x][y];c[x][y]=c[x-1][y];c[x-1][y]=t;x--;}else bz=1;break;
case 'B':if(isalpha(c[x+1][y])){t=c[x][y];c[x][y]=c[x+1][y];c[x+1][y]=t;x++;}else bz=1;break;
case 'R':if(isalpha(c[x][y+1])){t=c[x][y];c[x][y]=c[x][y+1];c[x][y+1]=t;y++;}else bz=1;break;
case 'L':if(isalpha(c[x][y-1])){t=c[x][y];c[x][y]=c[x][y-1];c[x][y-1]=t;y--;}else bz=1;break;
}
}
if(n>1)
printf("\n");
printf("Puzzle #%d:\n",n++);
if(bz)
printf("This puzzle has no final configuration.\n");
else
{
for(i=0;i<5;i++)
{
for(j=0;j<4;j++)
{
printf("%c ",c[i][j]);
}
printf("%c\n",c[i][4]);
}
}
gets(c[0]);
}
return 0;
}
上一篇: InfluxDB-InfluxQL基础语法教程--INTO子句
下一篇: javadoc生成方法
推荐阅读
-
团体队列 UVA540 Team Queue
-
丑数(Ugly Numbers, UVa 136)
-
破损的键盘(悲剧文本)(Broken Keyboard(a.k.a. Beiju Text),Uva 11988)
-
python 游戏(记忆拼图Memory_Puzzle)
-
POJ 2983 M × N Puzzle
-
爆笑之逗B剧场第227季
-
poj-1651 multiplication puzzle(区间dp)
-
集合栈计算机(The SetStack Computer, ACM/ICPC NWERC 2006,Uva12096)
-
bzoj3678 Katu Puzzle
-
唯一的雪花(Unique snowflakes,UVa 11572)滑动窗口+set