【习题 3-5 UVA-227】Puzzle
【链接】  我是链接,点我呀:) 
 【题意】
在这里输入题意
【题解】
模拟题。。
输入稍微恶心了点。
getchar()一个一个搞就好。
【代码】
#include <bits/stdc++.h>
using namespace std;
const int N = 5;
string s[N + 5],s2;
char S[N + 5][N + 5];
int x, y;
bool ok()
{
	bool ok = true;
	for (char key = getchar();key !='0';key = getchar())
	{
		if (!ok) continue;
		int x2 = x, y2 = y;
		switch (key)
		{
			case 'A':
			{
				x2--;
				break;
			}
			case 'B':
			{
				x2++;
				break;
			}
			case 'L':
			{
				y2--;
				break;
			}
			case 'R':
			{
				y2++;
				break;
			}
		default:
			break;
		}
		if (x2 <= 0 || x2 >= 6 || y2 <= 0 || y2 >= 6) {
			ok = false; continue;
		}
		swap(S[x][y], S[x2][y2]);
		x = x2, y = y2;
	}
	getchar();
	return ok;
}
int main()
{
	/*freopen("F:\\rush.txt", "r", stdin);*/
	int kase = 0;
	while (getline(cin,s[1]) && s[1][0]!='Z')
	{
		if (kase > 0) puts("");
		kase++;
		printf("Puzzle #%d:\n",kase);
		for (int i = 2; i <= 5; i++) getline(cin, s[i]);
		for (int i = 1; i <= 5; i++)
			for (int j = 1; j <= 5; j++)
			{
				S[i][j] = s[i][j - 1];
				if (S[i][j] == ' ')
				{
					x = i, y = j;
				}
			}
		if (ok())
		{
			for (int i = 1; i <= 5; i++)
				for (int j = 1; j <= 5; j++)
				{
					cout << S[i][j];
					if (j == 5) cout << endl;
					else cout << ' ';
				}
		}
		else
			cout << "This puzzle has no final configuration." << endl;
	}
	return 0;
}
												
											【习题 3-5 UVA-227】Puzzle的更多相关文章
- uva 227 Puzzle
		
Puzzle A children's puzzle that was popular 30 years ago consisted of a 5x5 frame which contained ...
 - UVA 227 Puzzle - 输入输出
		
题目: acm.hust.edu.cn/vjudge/roblem/viewProblem.action?id=19191 这道题本身难度不大,但输入输出时需要特别小心,一不留神就会出问题. 对于输入 ...
 - UVA 227 Puzzle(基础字符串处理)
		
题目链接: https://cn.vjudge.net/problem/UVA-227 /* 问题 输入一个5*5的方格,其中有一些字母填充,还有一个空白位置,输入一连串 的指令,如果指令合法,能够得 ...
 - uva 227 Puzzle (UVA - 227)
		
感慨 这个题实在是一个大水题(虽然说是世界决赛真题),但是它给出的输入输出数据,标示着老子世界决赛真题虽然题目很水但是数据就能卡死你...一直pe pe直到今天上午AC...无比感慨...就是因为最后 ...
 - Puzzle UVA - 227 PE代码求大佬指点
		
 A children's puzzle that was popular 30 years ago consisted of a 5×5 frame which contained 24 smal ...
 - UVA 277 Puzzle
		
题意:输入5x5的字符串,输入操作,要求输出完成操作后的字符串. 注意:①输入的操作执行可能会越界,如果越界则按题目要求输出不能完成的语句. ②除了最后一次的输出外,其他输出均要在后面空一行. ③操作 ...
 - 习题3-5 谜题(Puzzle, ACM/ICPC World Finals 1993, UVa227)
		
#include<stdio.h> #include<string.h> char s[5][5]; int main() { while(gets(s[0])) { int ...
 - UVA 227 周期串
		
题意: 给一个字符串,寻找最短的循环节 如abcabcabcabc以3为周期,也按6和12为周期. 分析: 因为循环节肯定是相等的,所以枚举串长度的所有约数的循环节再判断是否相等即可. 我的方法是枚举 ...
 - 【习题 7-8 UVA-12107】Digit Puzzle
		
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 迭代加深搜索. 枚举最大层数.(也即改变的数字个数 然后枚举第一个改哪个数字,第二个改哪个数字.. 一定要注意字典序问题. 每次优先 ...
 - Uva227.Puzzle
		
题目连接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...
 
随机推荐
- The ORDER BY clause is invalid in views, inline functions, derived tables, subqueries, and common table expressions, unless TOP or FOR XML is also specified.
			
https://stackoverflow.com/questions/30045871/sorting-the-view-based-on-frequency-in-sql-server Just ...
 - button按钮怎么实现超链接
			
button按钮怎么实现超链接 一.总结 1.我的按钮实现超链接是通过button内嵌a标签来实现的 <button class="am-btn am-btn-default am-b ...
 - amaze ui中的icon button
			
amaze ui中的icon button 说明几点: 1.链接效果 连接效果的本质一般都是a标签,好像很多button的链接效果都是用的a标签,submit表单提交或者button的type为sub ...
 - Exercise: PCA in 2D
			
Step 0: Load data The starter code contains code to load 45 2D data points. When plotted using the s ...
 - ZJOI2008骑士
			
Z国的骑士团是一个很有势力的组织,帮会中汇聚了来自各地的精英.他们劫富济贫,惩恶扬善,受到社会各界的赞扬. 最近发生了一件可怕的事情,邪恶的Y国发动了一场针对Z国的侵略战争.战火绵延五百里,在和平环境 ...
 - 【DRF序列化】
			
目录 基本的序列化操作 外键/多对多关系的序列化 反序列化的操作 单条数据查询及更新 数据的校验 单个字段的校验 多个字段的校验 自定义校验器 终极用法 ModelSerializer 前后端分离后, ...
 - ArcGIS Engine中空间参照(地理坐标)相关方法总结
			
转自原文 ArcGIS Engine中空间参照(地理坐标)相关方法总结 1.创建空间参考 /// <summary> /// 根据prj文件创建空间参考 /// </summary& ...
 - 怎样扩展Chromium各层的接口
			
加入新功能时,可能须要添加各层的接口,接口怎样加?必定须要向Chromium的原则看齐. 首先Chromium的模块设计遵循依赖倒置原则,上层模块依赖于低层模块.低层模块不会依赖上层模块的实现. 再者 ...
 - 使用wget工具抓取网页和图片 及 相关工具几个
			
想保存一些网页,最后找到这 wget 的 shell脚本,虽然不是太理想,亲测可用呢. 使用wget工具抓取网页和图片 来源 https://my.oschina.net/freestyletim ...
 - 35.Intellij IDEA设置忽略部分类编译错误
			
转自:https://www.aliyun.com/jiaocheng/290360.html 有些时候我们的项目中有些错误,但这些错误并不影响项目的整体运行(或许是没有使用到),默认情况下idea是 ...