Advertisement
vovanhoangtuan

Robot

Jun 4th, 2020
1,225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.08 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace Robot_p42
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int x, y;
  14.             string s = "";
  15.             readInput(out x, out y, out s);
  16.             task(ref x, ref y, s);
  17.             Console.WriteLine(x + " " + y);
  18.         }
  19.  
  20.         static void task(ref int x, ref int y, string s)
  21.         {
  22.             int step = 0;
  23.  
  24.             foreach (char buoc in s)
  25.             {
  26.                 if (step == 4) step = 0;
  27.                 else if (step == -1) step = 3;
  28.  
  29.                 move(step, buoc, ref x, ref y);
  30.  
  31.                 if (buoc == 'L') step++;
  32.                 else if (buoc == 'R') step--;
  33.             }
  34.         }
  35.  
  36.         static void move(int mat, char buoc, ref int x, ref int y)
  37.         {
  38.             if (mat == 0)
  39.             {
  40.                 if (buoc == 'F') x++;
  41.                 else if (buoc == 'B') x--;
  42.                 else if (buoc == 'R') y--;
  43.                 else if (buoc == 'L') y++;
  44.             }
  45.             else if (mat == 1)
  46.             {
  47.                 if (buoc == 'F') y++;
  48.                 else if (buoc == 'B') y--;
  49.                 else if (buoc == 'R') x++;
  50.                 else if (buoc == 'L') x--;
  51.             }
  52.             else if (mat == 2)
  53.             {
  54.                 if (buoc == 'F') x--;
  55.                 else if (buoc == 'B') x++;
  56.                 else if (buoc == 'R') y++;
  57.                 else if (buoc == 'L') y--;
  58.             }
  59.             else if (mat == 3)
  60.             {
  61.                 if (buoc == 'F') y--;
  62.                 else if (buoc == 'B') y++;
  63.                 else if (buoc == 'R') x--;
  64.                 else if (buoc == 'L') x++;
  65.             }
  66.            
  67.         }
  68.  
  69.         static void readInput(out int x, out int y, out string s)
  70.         {
  71.  
  72.             string[] temp = Console.ReadLine().Split();
  73.             x = int.Parse(temp[0]);
  74.             y = int.Parse(temp[1]);
  75.             s = Console.ReadLine();
  76.  
  77.         }
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement