UVa227 Puzzle
来源:互联网 发布:知乎中国出口构成 编辑:程序博客网 时间:2024/05/23 18:31
这题的坑点就是换行和交换时候都要检查一遍
下面上代码
#include<cstdio>#include<cstring>#include<iostream>using namespace std;char pic[10][10];char order[100];bool flag = false;bool isRange(int a){ if(a < 0 || a >=5){ flag = true; return false; } return true;}void solve(){ int x = 0, y = 0; for(int i = 0; i < 5; ++i){ for(int j = 0; j < 5; ++j){ if(pic[i][j] == ' '){ x = i; y = j; break; } } } for(int i = 0; order[i] != '0'; ++i){ char temp; if(order[i] == 'A'){ x--; if(!isRange(x)) break; swap(pic[x][y], pic[x + 1][y]); }else if(order[i] == 'R'){ y++; if(!isRange(y)) break; swap(pic[x][y], pic[x][y - 1]); }else if(order[i] == 'B'){ x++; if(!isRange(x)) break; swap(pic[x][y], pic[x - 1][y]); }else if(order[i] == 'L'){ y--; if(!isRange(y)) break; swap(pic[x][y], pic[x][y + 1]); } }}int main(){ int T = 0; while(gets(pic[0])){ memset(order, 0, sizeof(order)); if(pic[0][0] == 'Z'){ break; } for(int i = 1; i < 5; ++i){ gets(pic[i]); } for(int i = 0; ; ++i){ scanf("%c", &order[i]); if(order[i] == '0') break; } getchar(); solve(); if (T++) printf("\n"); printf("Puzzle #%d:\n", T); if(flag){ printf("This puzzle has no final configuration.\n"); flag = false; continue; } for(int i = 0; i < 5; ++i){ printf("%c", pic[i][0]); for(int j = 1; j < 5; ++j){ printf(" %c", pic[i][j]); } printf("\n"); } } return 0;}
0 0
- Uva227 - Puzzle
- Uva227.Puzzle
- UVA227-Puzzle
- UVa227 Puzzle
- uva227 - Puzzle
- Puzzle,UVa227
- uva227 - Puzzle
- [UVA227]Puzzle
- UVA227 puzzle
- UVa227 Puzzle
- UVA227 Puzzle
- UVa227 Puzzle
- UVa227:Puzzle
- UVa227 Puzzle
- UVa227 - Puzzle
- Uva227-Puzzle
- uva227 puzzle
- UVa227-Puzzle
- [LeetCode]problem 3. Longest Substring Without Repeating Characters
- 中括号在正则表达式中的多义性
- Python学习零碎比较
- JavaScript检测之basevalidate.js
- leetcode 347. Top K Frequent Elements 解题报告
- UVa227 Puzzle
- 如何移植μC/GUI在OLED12864上显示
- java数据写入数据库错误
- 基于c#环境的单片机和PC串口通信
- Linux spi驱动 (一)
- digester使用
- Android Annotations 4.0.0 配置Rest API
- [58] Length of Last Word
- UVa1601 万圣节后的早晨(The Morning after Halloween)