uva 227 模拟题

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <ctime>
#include <stack>
using namespace std;
//ios::sync_with_stdio(false);
char a[10][10];

char tma[10];

int main()
{
	int t = 1;
	//freopen("out.txt","w",stdout);
	//freopen("in.txt","r",stdin);

	while(1)
	{
		gets(tma);
		if(strlen(tma) == 1 && tma[0] == 'Z'){	
			break;
		}
		for(int i = 0;i < 5;i++)
		{
			if(tma[i] == '\0')
					tma[i] = ' ';
			a[0][i] = tma[i];
		}
		for(int i = 1;i < 5;i++)
		{
			gets(tma);
			for(int j =0 ;j < 5;j++)
			{
				if(tma[j] == '\0')
					tma[j] = ' ';
				a[i][j] = tma[j];
			}
		}
		int sx,sy;
		for(int i = 0;i < 5;i++)
		{
			for(int j = 0;j < 5;j++)
			{
				if(a[i][j] == ' '){
					sx = i;
					sy = j;
				}
			}
		}
		char op;
		int flag = 0;
		while(op = getchar(),op != '0')
		{
			int nx = sx ,ny= sy;
			switch (op){
				case 'A':
					{
						nx --;
						break;
					}
				case 'B':
					{
						nx ++;
						break;
					}
				case 'R':
					{
						ny ++;
						break;
					}
				case 'L':
					{
						ny --;
						break;
					}
				default:
					{
						continue;
					}
				
			}
			if(flag) continue;
			if(nx < 0 || nx >= 5 || ny < 0 || ny >= 5){
				flag = 1;
				continue;
			}
			else{
				swap(a[sx][sy],a[nx][ny]);
				sx = nx;
				sy = ny;
			}
			
		}
		
		if(t != 1)
			printf("\n");
		printf("Puzzle #%d:\n",t++);
		if(flag){
			printf("This puzzle has no final configuration.\n");
		}
		else	
		for(int i = 0;i < 5;i++)
		{
			for(int j = 0;j < 5;j++)
			{
				if(j!= 0)
					printf(" ");
				printf("%c",a[i][j]);
			}
			printf("\n");
		}
		getchar(); 
	}
	return 0;

}
长期因为在输出最后的提示串的时候发现自己少复制了一个‘.’已经不是一次啦!真是错都不知道自己是哪里错了!水!!!
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值