此题为一个简单模拟
代码如下:
#include<iostream>
using namespace std;
int main()
{
int m, n, map[105][105], i, j, x, y, k;
char s;
cin >> m >> n;
for (i = 0; i < m; i++)
for (j = 0; j < n; j++)
cin >> map[i][j];
cin >> x >> y >> s >> k;
for (; k > 0; k--)
{
if (s == 'U')
{
if (map[x][y] == 1)
{
s = 'R';
map[x][y] = 0;
y++;
}
else
{
s = 'L';
map[x][y] = 1;
y--;
}
}
else if (s == 'D')
{
if (map[x][y] == 1)
{
s = 'L';
map[x][y] = 0;
y--;
}
else
{
s = 'R';
map[x][y] = 1;
y++;
}
}
else if (s == 'L')
{
if (map[x][y] == 1)
{
s = 'U';
map[x][y] = 0;
x--;
}
else
{
s = 'D';
map[x][y] = 1;
x++;
}
}
else
{
if (map[x][y] == 1)
{
s = 'D';
map[x][y] = 0;
x++;
}
else
{
s = 'U';
map[x][y] = 1;
x--;
}
}
}
cout << x << y;
return 0;
}