文章
3
粉丝
36
获赞
6
访问
3.2k
#include<iostream>
#include<cstring>
using namespace std;
const int N = 20;
char map[N][N];
bool st[N][N];
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
int main()
{
int n,m;
while(cin>>n>>m)
{
memset(map,'*',sizeof map);
memset(st, 0, sizeof st);
char dir;
int x, y;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cin>>map[i][j];
if(map[i][j]!='.' && map[i][j]!='*')
{
dir = map[i][j];
x = i, y = j;
}
}
}
int idx;
if(dir=='U') idx = 0;
else if(dir=='D') idx = 2;
else if(dir=='L') idx = 3;
else idx = 1;
int cnt=1;
st[x][y] = true;
while(1)
{
int nx = x + dx[idx], ny = y + dy[idx]...
登录后发布评论
idx = 0的时候对应的不应该是向左的情况吗,为什么第33行是U(上)