题目:

题目浏览传送门

题意:

给出一个5*5的方格,里边有一个格子是空的,现在给出一串指令,A->空格向上移动,B->空格向下移动,R->空格向右移动,L->空格向左移动。

输出移动后的结果。

思路:

直接上模拟就好了,不过就是输入处理有点恶心,最好用scanf和printf来处理输入输出。

1、空格移动出界和出现不是‘A’、‘B’、‘R’、‘L’中的指令,这两种情况都算是“This puzzle has no final configuration.”。

2、另外在处理指令的时候,遇到1中的情况只要标记一下就好了,最终统一在‘0’的位置退出循环。(WA到怀疑人生)

例如这个样例:

AAAAA
BBBBB
NNNNN
JJJJJ
UUUU
AQ
0
Z

3、输出两两之间用一个空行隔开。

代码:

#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define FRE() freopen("in.txt","r",stdin)
using namespace std;
typedef long long ll;
const int maxn = 5e3+;
int mp[][]; void toSwap(int& a,int& b){
int t = a;
a = b,b = t;
} bool Move(char op, int& r,int& c) {
if(op=='A') {
if(r- == )
return false;
toSwap(mp[r][c],mp[r-][c]);
r--;
return true;
} else if(op=='B') {
if(r+ == )
return false;
toSwap(mp[r][c],mp[r+][c]);
r++;
return true;
} else if(op == 'R') {
if(c+ == )
return false;
toSwap(mp[r][c],mp[r][c+]);
c++;
return true;
} else if(op == 'L'){
if(c- == )
return false;
toSwap(mp[r][c],mp[r][c-]);
c--;
return true;
}
return false;
} void check() {
for(int i = ; i<=; i++) {
for(int j = ; j<=; j++) {
if(j!=)
printf(" ");
printf("%c",mp[i][j]+'A');
}
printf("\n");
}
} int main() {
//FRE();
char str[];
int cnt = ;
while() {
int len;
for(int i = ; i<=; i++) {
gets(str);
len = strlen(str);
if(i == && len == && str[] == 'Z'){
return ;
}
for(int j = ; j<len; j++) {
mp[i][j+] = str[j]-'A';
}
if(len == ){
mp[i][] = -;
}
}
int r,c;
for(int i = ; i<=; i++) {
for(int j = ; j<=; j++) {
if(mp[i][j] < ) {
r = i;
c = j;
}
}
}
//check();
char op[];
bool ok = true;
while() {
bool isend = false;
gets(op);
//cout<<op<<" GG "<<endl;
len = strlen(op);
for(int i = ; i<len; i++) {
//cout<<op[i]<<endl;
if(op[i] == '') {
isend = true;
}
else if(!Move(op[i],r,c)){
ok = false;
}
}
if(isend) {
break;
}
}
//cout<<"HH"<<endl;
if(cnt != ){
printf("\n");
}
if(!ok){
printf("Puzzle #%d:\n",++cnt);
printf("This puzzle has no final configuration.\n");
}else {
printf("Puzzle #%d:\n",++cnt);
check();
}
}
return ;
}
/*
PutIn:
TRGSJ
XDOKI
M VLN
WPABE
UQHCF
ARRBBL0
ABCDE
FGHIJ
KLMNO
PQRS
TUVWX
AAA
LLLL0
ABCDE
FGHIJ
KLMNO
PQRS
TUVWX
AAAAABBRRRLL0
Z
PutOut:
Puzzle #1:
T R G S J
X O K L I
M D V B N
W P A E
U Q H C F
Puzzle #2:
A B C D
F G H I E
K L M N J
P Q R S O
T U V W X
Puzzle #3:
This puzzle has no final configuration.
*/

UVA-227 Puzzle(模拟)的更多相关文章

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

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

  2. uva 227 Puzzle

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

  3. UVA 227 Puzzle - 输入输出

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

  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 246 - 10-20-30 (模拟+STL)

    UVA 246 - 10-20-30 题目链接 题意:给52张的扑克堆,先从左往右发7张牌,之后连续不断从左往右发7张牌,假设有牌堆形成了下面3种情况(按顺序推断): 1.头两张+尾一张和为10或20 ...

  7. ZOJ 2610 Puzzle 模拟

    大模拟:枚举6个方向.检查每一个0是否能移动 Puzzle Time Limit: 2 Seconds      Memory Limit: 65536 KB Little Georgie likes ...

  8. UVa 11988 (数组模拟链表) Broken Keyboard (a.k.a. Beiju Text)

    题意: 模拟一个文本编辑器,可以输入字母数字下划线,如果遇到'['则认为是Home键,如果是']'则认作End键. 问最终屏幕上显示的结果是什么字符串. 分析: 如果在数组用大量的移动字符必然很耗时. ...

  9. UVA 277 Puzzle

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

  10. UVa 1611 (排序 模拟) Crane

    假设数字1~i-1已经全部归位,则第i到第n个数为无序区间. 如果i在无序区间的前半段,那么直接将i换到第i个位置上. 否则先将i换到无序区间的前半段,再将i归位.这样每个数最多操作两次即可归位. # ...

随机推荐

  1. struts 模块化

    <struts> <!-- 包含了三个配置文件 --> <!-- 不指定路径默认在src下时的方式 --> <include file="strut ...

  2. 解决Eclipse alt+/不出来提示的问题

    1. 检查windows ——preferences ——java ——editor —— content assist - advanced,在右上方有一行“select the proposal ...

  3. H264 层次构成[2]

    H264层次构成 H264标准是由JVT(Joint Video Team,视频联合工作组)组织提出的新一代数字视频编码标准.JVT于2001年12月在泰国Pattaya成立.它由ITU-T的VCEG ...

  4. [翻译]NUnit---Equality Asserts&& Identity Asserts (四)

    Equality Asserts 这些方法测试两个参数是否相等.语言不自动装修的普通类型可以使用对应的重载的方法. Comparing Numerics of Different Types 比较两个 ...

  5. [Advance] How to debug a program (上)

    Tool GDB Examining Memory (data or in machine instructions) You can use the command x (for “examine” ...

  6. 洛谷P1600 天天爱跑步——树上差分

    题目:https://www.luogu.org/problemnew/show/P1600 看博客:https://blog.csdn.net/clove_unique/article/detail ...

  7. Swift5.1 语言指南(二十九)高级运算符

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  8. 学习http协议的三次握手和四次挥手 ~~笔记

    http协议是基于tcp协议的  所以应该说是tcp协议的三次握手和四次挥手 SYN:请求建立连接,并在其序列号的字段进行序列号的初始值设定.建立连接,设置为1 FIN:用来释放一个连接.FIN=1表 ...

  9. Asp.NET 知识点总结(一)

    1.简述 private. protected. public. internal 修饰符的访问权限. 答 . private : 私有类,私有成员, 在类的内部才可以访问. protected : ...

  10. 二分搜索 POJ 3258 River Hopscotch

    题目传送门 /* 二分:搜索距离,判断时距离小于d的石头拿掉 */ #include <cstdio> #include <algorithm> #include <cs ...