You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

162 lines
3.5 KiB
C++

#define _CRT_SECURE_NO_WARNINGS
#define _SILENCE_CXX17_C_HEADER_DEPRECATION_WARNING
#include <bits/stdc++.h>
#define R 3
#define U 0
#define D 1
#define L 2
using namespace std;
int nxt[4][2] = {{0, 1}, {0, -1}, {-1, 0}, {1, 0}};
char mp[20][20];
int n;
bool tex(int x, int y)
{
if (x <= n && x >= 1 && y >= 1 && y <= n)
{
if (mp[x][y] != '#')
return true;
else
return false;
}
return false;
}
void tx(int x, int y) {
if (tex(x-1,y)&&mp[x-1][y]=='T')
}
int main()
{
scanf("%d", &n);
int sx, sy, tx, ty;
for (int i = 1; i <= n; i++)
{
scanf("%s", mp[i]);
for (int j = n; j > 0; j--)
{
mp[i][j] = mp[i][j - 1];
if (mp[i][j] == 'S')
{
sx = i;
sy = j;
}
if (mp[i][j] == 'T')
{
tx = i;
ty = j;
}
}
}
int nx = sx, ny = sy, tohe = R;
int wx = sx, wy = sy + 1;
while (mp[nx][ny] != 'T')
{
if (tohe == R)
{
if (tex(nx + 1, ny + 1) && tex(nx , ny+1) )
{
printf("D");
tohe = D;
nx = nx + 1;
ny = ny + 1;
}
else if (tex(nx, ny+1))
{
printf("D");
nx = nx + 1;
}
else if (tex(nx-1, ny))
{
printf("D");
tohe = U;
}
else
{
printf("D");
tohe = L;
}
}
else if (tohe == U)
{
if (tex(nx - 1, ny + 1) && tex(nx - 1, ny) )
{
printf("R");
tohe = D;
nx = nx - 1;
ny = ny + 1;
}
else if (tex(nx - 1, ny))
{
printf("R");
nx = nx - 1;
}
else if (tex(nx, ny - 1))
{
printf("R");
tohe = L;
}
else
{
printf("R");
tohe = D;
}
}
else if (tohe == L)
{
if (tex(nx - 1, ny - 1) && tex(nx, ny-1) )
{
printf("U");
tohe = U;
nx = nx - 1;
ny = ny - 1;
}
else if (tex(nx, ny-1))
{
printf("U");
ny = ny - 1;
}
else if (tex(nx+1, ny))
{
printf("U");
tohe = D;
}
else
{
printf("U");
tohe = R;
}
}
else if (tohe == D)
{
if (tex(nx + 1, ny - 1) && tex(nx + 1, ny) )
{
printf("L");
tohe = L;
nx = nx + 1;
ny = ny - 1;
}
else if (tex(nx + 1, ny))
{
printf("L");
nx = nx + 1;
}
else if (tex(nx, ny + 1))
{
printf("L");
tohe = R;
}
else
{
printf("L");
tohe = U;
}
}
}
return 0;
}