代码:
#include<iostream>
using namespace std;
#define LEN 10010
int r,c,ans,q[LEN][4];
char a[100][100];
string s[1100];
int dx[]={0,-1,0,1,0};
int dy[]={0,0,1,0,-1};
int check(string s1){
if(s1[0]=='N') return 1;
if(s1[0]=='E') return 2;
if(s1[0]=='S') return 3;
if(s1[0]=='W') return 4;
//return 0;
}
void bfs(int x,int y){
int h=0,t=1,step,f=0;
q[h][1] = x;
q[h][2] = y;
q[h][3] = 0;
while(h!=t){
x = q[h][1];
y = q[h][2];
step = q[h][3];
if(step==ans) a[x][y] = '*';
for(int i=step;i<=step+1;i++){
if(i==0||i==ans+1) continue;
int f=check(s[i]);
int fx=x+dx[f];
int fy=y+dy[f];
if(fx>=1&&fx<=r&fy>=1&&fy<=c&&a[fx][fy]!='X'){
q[t][1] = fx;
q[t][2] = fy;
q[t][3] = i;
t = (t+1)%LEN;
}
}
h = (h+1)%LEN;
}
}
int main(){
int x,y;
cin>>r>>c;
for(int i=1;i<=r;i++){
for(int j=1;j<=c;j++){
cin>>a[i][j];
if(a[i][j]=='*'){
a[i][j] = '.';
x = i;
y = j;
}
}
}
cin>>ans;
for(int i=1;i<=ans;i++){
cin>>s[i];
}
bfs(x,y);
for(int i=1;i<=r;i++){
for(int j=1;j<=c;j++){
cout<<a[i][j];
}
cout<<endl;
}
return 0;
}
*/