#include <vector> #include <iostream> #include <string> using namespace std; int main() { vector<vector<char>> map = { { 'T', 'R', 'G', 'S', 'J' }, { 'X', 'D', 'O', 'K', 'I' }, { 'M', ' ', 'V', 'L', 'N' }, { 'W', 'P', 'A', 'B', 'E' }, { 'U', 'Q', 'H', 'C', 'F' } }; string word; cin >> word; bool not_legal = 0; int x = 2, y = 1; //空格位置 for (auto a : word) { if (a == '0') break; switch (a) { case 'A': if (x == 0) { not_legal = 1; break; } map[x][y] = map[x-1][y]; x--; map[x][y] = ' '; break; case 'B': if (x == 4) { not_legal = 1; break; } map[x][y] = map[x + 1][y]; x++; map[x][y] = ' '; break; case 'L': if (y == 0) { not_legal = 1; break; } map[x][y] = map[x][y-1]; y--; map[x][y] = ' '; break; case 'R': if (y == 4) { not_legal = 1; break; } map[x][y] = map[x][y+1]; y++; map[x][y] = ' '; break; } } if (not_legal) cout << "This puzzle has no final configuration." << endl; else { for (auto a : map) { for (auto c : a) cout << c << " "; cout << endl; } } return 0; }
3-5 谜题 UVa227
猜你喜欢
转载自blog.csdn.net/fuwu4087/article/details/80382040
今日推荐
周排行