题目链接:
http://mozhu.today/#/problem/show/758
题目代码:
#include "iostream"
#include "stdio.h"
using namespace std;
int main()
{
int T,i,j;
int x, y, t, x0, y0;
int result[101] = { 0 };
char path[100001];
cin >> T;
for (i = 0;i < T;i++)
{
cin >> x >> y >> t;
cin >> path;
j = 0;
x0 = 0;
y0 = 0;
while (path[j] != '\n')
{
if ((x0 == x) && (y0 == y))
break;
if (x >= 0 && y >= 0)
{
if ((path[j] == 'R') && (x0 < x))
{
x0++;
if ((++result[i]) > t)
{
result[i] = -1;
break;
}
}
else if ((path[j] == 'U') && (y0 < y))
{
y0++;
if ((++result[i]) > t)
{
result[i] = -1;
break;
}
}
else if ((++result[i]) > t)
{
result[i] = -1;
break;
}
}
if (x >= 0 && y < 0)
{
if ((path[j] == 'R') && (x0 < x))
{
x0++;
if ((++result[i]) > t)
{
result[i] = -1;
break;
}
}
else if ((path[j] == 'D') && (y0 > y))
{
y0--;
if ((++result[i]) > t)
{
result[i] = -1;
break;
}
}
else if ((++result[i]) > t)
{
result[i] = -1;
break;
}
}
if (x < 0 && y >= 0)
{
if ((path[j] == 'L') && (x0 > x))
{
x0--;
if ((++result[i]) > t)
{
result[i] = -1;
break;
}
}
else if ((path[j] == 'U') && (y0 < y))
{
y0++;
if ((++result[i]) > t)
{
result[i] = -1;
break;
}
}
else if ((++result[i]) > t)
{
result[i] = -1;
break;
}
}
if (x < 0 && y < 0)
{
if ((path[j] == 'L') && (x0 > x))
{
x0--;
if ((++result[i]) > t)
{
result[i] = -1;
break;
}
}
else if ((path[j] == 'D') && (y0 > y))
{
y0--;
if ((++result[i]) > t)
{
result[i] = -1;
break;
}
}
else if((++result[i]) > t)
{
result[i] = -1;
break;
}
}
j++;
}
}
for (i = 0;i < T;i++)
cout << result[i] << endl;
return 0;
}