【链接】 我是链接,点我呀:)

【题意】

在这里输入题意

【题解】

模拟题。。
输入稍微恶心了点。
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的更多相关文章

  1. uva 227 Puzzle

     Puzzle  A children's puzzle that was popular 30 years ago consisted of a 5x5 frame which contained ...

  2. UVA 227 Puzzle - 输入输出

    题目: acm.hust.edu.cn/vjudge/roblem/viewProblem.action?id=19191 这道题本身难度不大,但输入输出时需要特别小心,一不留神就会出问题. 对于输入 ...

  3. UVA 227 Puzzle(基础字符串处理)

    题目链接: https://cn.vjudge.net/problem/UVA-227 /* 问题 输入一个5*5的方格,其中有一些字母填充,还有一个空白位置,输入一连串 的指令,如果指令合法,能够得 ...

  4. uva 227 Puzzle (UVA - 227)

    感慨 这个题实在是一个大水题(虽然说是世界决赛真题),但是它给出的输入输出数据,标示着老子世界决赛真题虽然题目很水但是数据就能卡死你...一直pe pe直到今天上午AC...无比感慨...就是因为最后 ...

  5. Puzzle UVA - 227 PE代码求大佬指点

    ​ A children's puzzle that was popular 30 years ago consisted of a 5×5 frame which contained 24 smal ...

  6. UVA 277 Puzzle

    题意:输入5x5的字符串,输入操作,要求输出完成操作后的字符串. 注意:①输入的操作执行可能会越界,如果越界则按题目要求输出不能完成的语句. ②除了最后一次的输出外,其他输出均要在后面空一行. ③操作 ...

  7. 习题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 ...

  8. UVA 227 周期串

    题意: 给一个字符串,寻找最短的循环节 如abcabcabcabc以3为周期,也按6和12为周期. 分析: 因为循环节肯定是相等的,所以枚举串长度的所有约数的循环节再判断是否相等即可. 我的方法是枚举 ...

  9. 【习题 7-8 UVA-12107】Digit Puzzle

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 迭代加深搜索. 枚举最大层数.(也即改变的数字个数 然后枚举第一个改哪个数字,第二个改哪个数字.. 一定要注意字典序问题. 每次优先 ...

  10. Uva227.Puzzle

    题目连接:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

随机推荐

  1. .Net 自动属性结合手动属性

    Model using System; using System.Collections.Generic; using System.Linq; using System.Web; namespace ...

  2. Python: PS 滤镜--扇形变换

    本文用 Python 实现 PS 滤镜中的一种几何变换特效,称为扇形变换,将图像扭曲成一个扇形,具体的算法原理和效果图可以参考以前的博客: http://blog.csdn.net/matrix_sp ...

  3. es6 --- Generator 函数

    第一部分,ES6 中的 Generator 在 ES6 出现之前,基本都是各式各样类似Promise的解决方案来处理异步操作的代码逻辑,但是 ES6 的Generator却给异步操作又提供了新的思路, ...

  4. How to anti-Obfuscated code

    Author:jin can zhu from China Source:http://blog.csdn.net/clever101 Now many software makers have us ...

  5. 分享一下事件监听addEventListener----attachEvent的用法

    来自:http://www.cnblogs.com/wkylin/archive/2011/10/09/2203161.html 事件监听addEventListener----attachEvent ...

  6. VMware Vsphere 6.0安装部署 总体部署架构

    (一)总体部署架构 本教程用于学习目的,力求详尽的介绍安装部署过程和各组件之间的关系,部署过程从最简单的模型开始,系列文章按时间顺序依次展开,每篇介绍一个组件. 开始阶段,按照一台物理服务器,部署所有 ...

  7. dp之多重背包(二进制优化)

    void solve(int v,int w,int c){    int count=0;    for(int k=1;k<=c;k<<=1)    {        val[c ...

  8. Mblog 部署手册

    准备工作 安装 JDK8 安装图片处理工具:GraphicsMagick1.3.20,下载地址 安装 Maven 准备 IDE (如果你不看源码,可以忽略下面的步骤,直接通过Maven编译war包) ...

  9. .Net中的缓存依赖配置

    缓存--能非常好的提高网站的性能. 在訪问量大,但更新较少的站点中使用缓存,能够大大提高执行效率. 在.net中给我们提供了非常好的缓存机制.页面缓存.数据缓存,还有非常好的依赖缓存. 依赖缓存优点就 ...

  10. 阿里云 django的一次web维护记录

    首先, 丢给我一个阿里云的server的账号/password,之前没有玩过阿里云,想想应该也是ssh服务来远程登陆. 环境: centos+nginx+uwsgi+python2.7+django. ...