kirililchev3

Debug Sequence of Command

Jun 3rd, 2018
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.14 KB | None | 0 0
  1. namespace Sequence_of_Commands
  2. {
  3.     using System;
  4.     using System.Linq;
  5.  
  6.     public class BrokenToFix
  7.     {
  8.         private const char ArgumentsDelimiter = ' ';
  9.  
  10.         public static void Main()
  11.         {
  12.             int sizeOfArray = int.Parse(Console.ReadLine());
  13.  
  14.             long[] array = Console.ReadLine()
  15.                 .Trim()
  16.                 .Split(ArgumentsDelimiter)
  17.                 .Select(long.Parse)
  18.                 .ToArray();
  19.  
  20.             string[] command = Console.ReadLine().Split(ArgumentsDelimiter);
  21.  
  22.             while (!command[0].Equals("stop"))
  23.             {
  24.                 PerformAction(array, command);
  25.                 Console.WriteLine(string.Join(" ", array));
  26.                 command = Console.ReadLine().Split(ArgumentsDelimiter);
  27.             }
  28.         }
  29.  
  30.         public static void PerformAction(long[] arr, string[] comand)
  31.         {
  32.             switch (comand[0].ToLower())
  33.             {
  34.                 case "multiply":
  35.                     arr[int.Parse(comand[1]) - 1] *= long.Parse(comand[2]);
  36.                     break;
  37.                 case "add":
  38.                     arr[int.Parse(comand[1]) - 1] += long.Parse(comand[2]);
  39.                     break;
  40.                 case "subtract":
  41.                     arr[int.Parse(comand[1]) - 1] -= long.Parse(comand[2]);
  42.                     break;
  43.                 case "lshift":
  44.                     ArrayShiftLeft(arr);
  45.                     break;
  46.                 case "rshift":
  47.                     ArrayShiftRight(arr);
  48.                     break;
  49.             }
  50.         }
  51.  
  52.         public static void ArrayShiftRight(long[] array)
  53.         {
  54.             long temp = array[array.Length - 1];
  55.             for (int i = array.Length - 1; i >= 1; i--)
  56.             {
  57.                 array[i] = array[i - 1];
  58.             }
  59.  
  60.             array[0] = temp;
  61.         }
  62.  
  63.         public static void ArrayShiftLeft(long[] array)
  64.         {
  65.             long temp = array[0];
  66.             for (int i = 0; i < array.Length - 1; i++)
  67.             {
  68.                 array[i] = array[i + 1];
  69.             }
  70.  
  71.             array[array.Length - 1] = temp;
  72.         }
  73.     }
  74. }
Advertisement
Add Comment
Please, Sign In to add comment