Advertisement
Guest User

Untitled

a guest
Nov 20th, 2017
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.13 KB | None | 0 0
  1. namespace LabProblem.Properties
  2. {
  3.     public class Class7
  4.     {
  5.         public class Soldier
  6.         {
  7.             public Soldier()
  8.             {
  9.                 Left = 0;
  10.                 Right = 0;
  11.             }
  12.  
  13.             public Soldier(int l, int r)
  14.             {
  15.                 Left = l;
  16.                 Right = r;
  17.             }
  18.  
  19.             public int Left;
  20.             public int Right;
  21.         }
  22.  
  23.         public static void Main()
  24.         {
  25.             var reader = new StreamReader("formation.in");
  26.             var writer = new StreamWriter("formation.out");
  27.             var nampm = reader.ReadLine().Split();
  28.             var n = int.Parse(nampm[0]);
  29.             var m = int.Parse(nampm[1]);
  30.             var row = new List<Soldier>();
  31.             for (var i = 0; i != 80000; i++)
  32.                 row.Add(new Soldier(-1, -1));
  33.             row[1].Left = 0;
  34.             row[1].Right = 0;
  35.             for (var i = 0; i != m; i++)
  36.             {
  37.                 var commandLine = reader.ReadLine().Split();
  38.                 if (commandLine[0] == "left")
  39.                 {
  40.                     if (row[int.Parse(commandLine[1])].Left == -1 && row[int.Parse(commandLine[1])].Right == -1)
  41.                     {
  42.                         if (row[int.Parse(commandLine[2])].Left != 0)
  43.                             row[row[int.Parse(commandLine[2])].Left].Right = int.Parse(commandLine[1]);
  44.                         row[int.Parse(commandLine[1])].Left = row[int.Parse(commandLine[2])].Left;
  45.                         row[int.Parse(commandLine[1])].Right = int.Parse(commandLine[2]);
  46.                         row[int.Parse(commandLine[2])].Left = int.Parse(commandLine[1]);
  47.                     }
  48.                 }
  49.                 else if (commandLine[0] == "right")
  50.                 {
  51.                     if (row[int.Parse(commandLine[1])].Left == -1 && row[int.Parse(commandLine[1])].Right == -1)
  52.                     {
  53.                         if (row[int.Parse(commandLine[2])].Right != 0)
  54.                             row[row[int.Parse(commandLine[2])].Right].Left = int.Parse(commandLine[1]);
  55.                         row[int.Parse(commandLine[1])].Right = row[int.Parse(commandLine[2])].Right;
  56.                         row[int.Parse(commandLine[1])].Left = int.Parse(commandLine[2]);
  57.                         row[int.Parse(commandLine[2])].Right = int.Parse(commandLine[1]);
  58.                     }
  59.                 }
  60.                 else if (commandLine[0] == "leave")
  61.                 {
  62.                     row[row[int.Parse(commandLine[1])].Left].Right = row[int.Parse(commandLine[1])].Right;
  63.                     row[row[int.Parse(commandLine[1])].Right].Left = row[int.Parse(commandLine[1])].Left;
  64.                     row[int.Parse(commandLine[1])].Left = -1;
  65.                     row[int.Parse(commandLine[1])].Right = -1;
  66.                 }
  67.                 else if (commandLine[0] == "name")
  68.                 {
  69.                     writer.WriteLine(row[int.Parse(commandLine[1])].Left + " " +
  70.                                      row[int.Parse(commandLine[1])].Right);
  71.                 }
  72.             }
  73.             writer.Close();
  74.         }
  75.     }
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement