欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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;
}

 

相关标签: switch