感觉上没啥问题,但就是错……
#include<bits/stdc++.h>
using namespace std;
int r,c,n,x,y,v[60][60][1010];
int dx[5]={0,1,-1,0,0};
int dy[5]={0,0,0,1,-1};
char s[60][60];
string str[1010];
struct node{int x,y,k;};
queue <node> q;
int si(string s)
{
if (s=="SOUTH") return 1;
if (s=="NORTH") return 2;
if (s=="EAST") return 3;
if (s=="WEST") return 4;
}
int main()
{
cin >> r >> c;
for (int i=1;i<=r;i++)
for (int j=1;j<=c;j++)
{
cin >> s[i][j];
if (s[i][j]=='*') x=i,y=j,s[i][j]='.';
}
cin >> n;
for (int i=1;i<=n;i++) cin >> str[i];
q.push(node{x,y,1});
while (!q.empty())
{
node h=q.front();
if (h.k==n+1)
{
s[h.x][h.y]='*';
q.pop();
continue;
}
int f=si(str[h.k]),xx=h.x,yy=h.y;
xx+=dx[f];
yy+=dy[f];
while (xx>=1&&xx<=c&&yy>=1&&yy<=r&&!v[xx][yy][h.k]&&s[xx][yy]!='X')
{
v[xx][yy][h.k]=1;
q.push(node{xx,yy,h.k+1});
xx+=dx[f];
yy+=dy[f];
}
q.pop();
}
for (int i=1;i<=r;i++)
{
for (int j=1;j<=c;j++) cout << s[i][j];
cout << endl;
}
return 0;
}