45pts WA+RE求助大佬
#include <bits/stdc++.h>
using namespace std;
char c[105][105];
int wox, woy, pos; // pos: ^1 >2 v3 <4
void changepos() {
if (pos == 1) c[wox][woy] = '^';
if (pos == 2) c[wox][woy] = '>';
if (pos == 3) c[wox][woy] = 'v';
if (pos == 4) c[wox][woy] = '<';
}
void go1(int x, int y) { // up
if (x == 0 || y == 0 || x == 9 || y == 9) return ;
if (c[x - 1][y] != '.') {
go1(x - 1, y);
}
c[x - 1][y] = c[x][y];
c[x][y] = '.';
}
void go2(int x, int y) { // right
if (x == 0 || y == 0 || x == 9 || y == 9) return ;
if (c[x][y + 1] != '.' && c[x - 1][y] != ' ') {
go2(x, y + 1);
}
c[x][y + 1] = c[x][y];
c[x][y] = '.';
}
void go3(int x, int y) { // down
if (x == 0 || y == 0 || x == 9 || y == 9) return ;
if (c[x + 1][y] != '.' && c[x + 1][y] != ' ') {
go3(x + 1, y);
}
c[x + 1][y] = c[x][y];
c[x][y] = '.';
}
void go4(int x, int y) { // left
if (x == 0 || y == 0 || x == 9 || y == 9) return ;
if (c[x][y - 1] != '.' && c[x][y - 1] != ' ') {
go4(x, y - 1);
}
c[x][y - 1] = c[x][y];
c[x][y] = '.';
}
void _move(int stp) {
if (pos == 1) {
for (int i = 1; i <= stp; i ++) {
go1(wox, woy);
wox --;
if (wox == 1) break;
}
}
if (pos == 2) {
for (int i = 1; i <= stp; i ++) {
go2(wox, woy);
woy ++;
if (woy == 8) break;
}
}
if (pos == 3) {
for (int i = 1; i <= stp; i ++) {
go3(wox, woy);
wox ++;
if (wox == 8) break;
}
}
if (pos == 4) {
for (int i = 1; i <= stp; i ++) {
go4(wox, woy);
woy --;
if (woy == 1) break;
}
}
}
int main() {
for (int i = 1; i <= 8; i ++) {
for (int j = 1; j <= 8; j ++) {
cin >> c[i][j];
if (c[i][j] == '^') wox = i, woy = j, pos = 1;
if (c[i][j] == '>') wox = i, woy = j, pos = 2;
if (c[i][j] == 'v') wox = i, woy = j, pos = 3;
if (c[i][j] == '<') wox = i, woy = j, pos = 4;
}
}
string s;
while (cin >> s && s != "#") {
if (s == "move") {
int step;
cin >> step;
_move(step);
}
if (s == "turn") {
string poss;
cin >> poss;
if (poss == "left") {
if (pos == 1) pos = 4;
else pos --;
}
if (poss == "right") {
if (pos == 4) pos = 1;
else pos ++;
}
if (poss == "back") {
if (pos == 1) pos = 3;
if (pos == 3) pos = 1;
if (pos == 2) pos = 4;
if (pos == 4) pos = 2;
}
}
changepos();
}
for (int i = 1; i <= 8; i ++) {
for (int j = 1; j <= 8; j ++) {
cout << c[i][j];
}
cout << endl;
}
return 0;
}