#include <iostream> #include <vector> #include <stack> #include <list> #include <map> #include <set> #include <deque> #include <queue> #include <cstring> #include <unordered_map> #include <unordered_set> #include <algorithm> #include <numeric> #include <chrono> #include <ctime> #include <cmath> #include <cctype> #include <string> #include <cstdio> #include <iomanip> #include <thread> #include <mutex> #include <condition_variable> #include <functional> #include <iterator> using namespace std; char matrix[5][7], order[1024]; int x, y, len = 0; bool IsOk(char in) {int nx = x, ny = y;switch (in){case 'A': nx = x - 1; break;case 'B': nx = x + 1; break;case 'L': ny = y - 1; break;case 'R': ny = y + 1; break;}if (nx < 0 || ny < 0 || nx >= 5 || ny >= 5) return false;swap(matrix[x][y], matrix[nx][ny]);x = nx;y = ny;return true; } bool Init() {memset(matrix, ' ', sizeof(matrix));//gets 也是可以的fgets(matrix[0],7,stdin);return true; } void GetStart() {for (int i = 0; i < 5; ++i) {for (int j = 0; j < 5; ++j) {//vs2013 上面 换行前一个是空格 不输入到字符串中 但是提交代码 可以不用判断 似乎空格也输入到字符串中了 gets fges getline 都是这种情况if (matrix[i][j] == ' ' || matrix[i][j] == 'n') {x = i;y = j;matrix[i][j] = ' ';return;}}} } int main() {int nCount = 0;while (Init() && matrix[0][0] != 'Z') {int canDo = 1;x = y = len = 0;for (int i = 1; i < 5; ++i) {fgets(matrix[i], 7, stdin);}GetStart();while (cin >> order[len] && order[len] != '0') ++len;cin.get();if (nCount) cout << endl;cout << "Puzzle #" << ++nCount << ":" << endl;for (int i = 0; i < len; ++i) {if (canDo && !IsOk(order[i])) {cout << "This puzzle has no final configuration." << endl; canDo = 0; break;}}if (!canDo) { continue; }for (int i = 0; i < 5; ++i) {cout << matrix[i][0];for (int j = 1; j < 5; ++j) {cout << " "<<matrix[i][j] ;}cout << endl;}}return 0; }
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111习题3
来源:
时间:2024-12-16 11:01最新推荐文章于 2023-07-09 21:37:58 发布
小刀刺大熊 于 2020-10-25 17:37:22 发布
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
相关知识
《5 凤仙花》习题
c语言函数习题
老王python之基本数据类型习题
社会调查研究方法习题及答案
2022年自考《园林植物遗传与育种》专项习题:简答2
基于马扎诺教育目标分类学的历史教科书习题分析 .pdf
数值分析学习利器:《数值分析(第5版)》习题解答
自学考试《盆景与花卉装饰》备考习题及答案
植物病理学习题与答案1
花卉应用学 习题
网址: 习题3 https://www.huajiangbk.com/newsview1123939.html
上一篇: 结婚5周年纪念日祝福语(精选25 |
下一篇: 山东人口抽样调查显示 男:女=1 |
推荐分享

- 1君子兰什么品种最名贵 十大名 4012
- 2世界上最名贵的10种兰花图片 3364
- 3花圈挽联怎么写? 3286
- 4迷信说家里不能放假花 家里摆 1878
- 5香山红叶什么时候红 1493
- 6花的意思,花的解释,花的拼音 1210
- 7教师节送什么花最合适 1167
- 8勿忘我花图片 1103
- 9橄榄枝的象征意义 1093
- 10洛阳的市花 1039
分享热点排名