Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace LabProblem.Properties
- {
- public class Class7
- {
- public class Soldier
- {
- public Soldier()
- {
- Left = 0;
- Right = 0;
- }
- public Soldier(int l, int r)
- {
- Left = l;
- Right = r;
- }
- public int Left;
- public int Right;
- }
- public static void Main()
- {
- var reader = new StreamReader("formation.in");
- var writer = new StreamWriter("formation.out");
- var nampm = reader.ReadLine().Split();
- var n = int.Parse(nampm[0]);
- var m = int.Parse(nampm[1]);
- var row = new List<Soldier>();
- for (var i = 0; i != 80000; i++)
- row.Add(new Soldier(-1, -1));
- row[1].Left = 0;
- row[1].Right = 0;
- for (var i = 0; i != m; i++)
- {
- var commandLine = reader.ReadLine().Split();
- if (commandLine[0] == "left")
- {
- if (row[int.Parse(commandLine[1])].Left == -1 && row[int.Parse(commandLine[1])].Right == -1)
- {
- if (row[int.Parse(commandLine[2])].Left != 0)
- row[row[int.Parse(commandLine[2])].Left].Right = int.Parse(commandLine[1]);
- row[int.Parse(commandLine[1])].Left = row[int.Parse(commandLine[2])].Left;
- row[int.Parse(commandLine[1])].Right = int.Parse(commandLine[2]);
- row[int.Parse(commandLine[2])].Left = int.Parse(commandLine[1]);
- }
- }
- else if (commandLine[0] == "right")
- {
- if (row[int.Parse(commandLine[1])].Left == -1 && row[int.Parse(commandLine[1])].Right == -1)
- {
- if (row[int.Parse(commandLine[2])].Right != 0)
- row[row[int.Parse(commandLine[2])].Right].Left = int.Parse(commandLine[1]);
- row[int.Parse(commandLine[1])].Right = row[int.Parse(commandLine[2])].Right;
- row[int.Parse(commandLine[1])].Left = int.Parse(commandLine[2]);
- row[int.Parse(commandLine[2])].Right = int.Parse(commandLine[1]);
- }
- }
- else if (commandLine[0] == "leave")
- {
- row[row[int.Parse(commandLine[1])].Left].Right = row[int.Parse(commandLine[1])].Right;
- row[row[int.Parse(commandLine[1])].Right].Left = row[int.Parse(commandLine[1])].Left;
- row[int.Parse(commandLine[1])].Left = -1;
- row[int.Parse(commandLine[1])].Right = -1;
- }
- else if (commandLine[0] == "name")
- {
- writer.WriteLine(row[int.Parse(commandLine[1])].Left + " " +
- row[int.Parse(commandLine[1])].Right);
- }
- }
- writer.Close();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement