4. 多台無人機操控系統

int N = int.Parse(Console.ReadLine());
var k = Console.ReadLine().Split(' ');

int mX = int.Parse(k[0]), mY = int.Parse(k[1]);

Dictionary<char, char> rotateR = new Dictionary<char, char>();
rotateR['N'] = 'E';
rotateR['E'] = 'S';
rotateR['S'] = 'W';
rotateR['W'] = 'N';

Dictionary<char, char> rotateL = new Dictionary<char, char>();
rotateL['N'] = 'W';
rotateL['W'] = 'S';
rotateL['S'] = 'E';
rotateL['E'] = 'N';

Dictionary<char, int[]> move = new Dictionary<char, int[]>();
move['N'] = new[] { 0, 1 };
move['E'] = new[] { 1, 0 };
move['S'] = new[] { 0, -1 };
move['W'] = new[] { -1, 0 };

string res = "";

for (int i = 0; i < N; i++)
{
    var data = Console.ReadLine().Split(' ');

    int x = int.Parse(data[0]), y = int.Parse(data[1]);
    char face = data[2][0];

    var path = Console.ReadLine().ToCharArray();
    bool kk = false;
    for (int j = 0; j < path.Length; j++)
    {
        switch (path[j])
        {
            case 'R':
                face = rotateR[face];
                break;
            case 'L':
                face = rotateL[face];
                break;
            case 'F':
                var loc = move[face];
                x += loc[0];
                y += loc[1];
                if (x >= mX || y >= mY)
                {
                    var s = x + " " + y + " " + face + " " + "Destroyed";
                    Console.WriteLine(s);
                    res += s + "\n";
                    kk = true;
                }
                break;
        }
        if (kk) break;
    }
    if (!kk)
    {
        var s = x + " " + y + " " + face;
        Console.WriteLine(s);
        res += s + "\n";
    }
}

if (res.Length != 0) res = res.Substring(0, res.Length - 1);
File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + "/output.txt", res);

Last updated