[C++] 纯文本查看 复制代码 #include <bits/stdc++.h>
using namespace std;
int main() {
char map[3][4] = {
'A', '0', '0', '0',
'0', '#', '#', '0',
'0', '#', '0', '0'
};
char a[100];
cin >> a;
int x = 0, y = 0;
for (int i = 0; i <= 2; i++) {
for (int j = 0; j <= 3; j++) {
cout << map[i][j] << " ";
}
cout << endl;
}
cout << endl;
map[0][0] = '0';
for (int i = 0; i < strlen(a); i++) {
switch (a[i]) {
case 'w':
if (x != 0 && map[x - 1][y] != '#') {
x = x - 1;
}
break;
case 'a':
if (y != 0 && map[x][y - 1] != '#') {
y = y - 1;
}
break;
case 's':
if (x != 2 && map[x + 1][y] != '#') {
x = x + 1;
}
break;
case 'd':
if (y != 3 && map[x][y + 1] != '#') {
y = y + 1;
}
break;
}
}
map[x][y] = 'A';
for (int i = 0; i <= 2; i++) {
for (int j = 0; j <= 3; j++) {
cout << map[i][j] << " ";
}
cout << endl;
}
return 0;
} |