char a[5][5]; //二维数字表示拼图 int key = 1,t=0; while (cin.get(a[0][0])&&a[0][0]!='Z') { if (++t>1) //用来控制输出中的空行,首行前和最后一行后无空行,输出用空行隔开 cout << endl; int c = 0, d = 0; //用来标记空白的位置 for (int i = 0; i < 5; ++i) { for (int j = 0; j < 5; ++j) { if (!i && !j)continue; cin.get(a[i][j]); if (a[i][j] == ' ') c = i, d = j; } cin.get(); //读取行尾的回车符 }
int i = 0; cout << "Puzzle #" << key++ <<':'<< endl; int flag = 0; //标记是否遇到非法命令 char s; while (cin.get(s) && s != '0') //模拟空格的移动,注意命令可能不在同一行 { if (flag == 1 || s == '\n') continue; switch (s) { case'A': if (c - 1 < 0) { flag = 1; break;