fbinnzhivko

04.00 Array Modifier

Apr 26th, 2016
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.65 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. class Program
  4. {
  5.     static void Main()
  6.     {
  7.         //Input - Splitting to Array
  8.         long[] input = Console.ReadLine().Split().Select(long.Parse).ToArray();
  9.  
  10.         //temp variable - to be used in the swap
  11.         long temp = 0;
  12.  
  13.         string checker = Console.ReadLine();
  14.         bool chck = checker.Contains("end");
  15.  
  16.         //While checker !contains "end"
  17.         while (chck != true)
  18.         {
  19.  
  20.             chck = checker.Contains("end");
  21.             bool multiply = checker.Contains("multiply");
  22.             bool swap = checker.Contains("swap");
  23.             bool decrease = checker.Contains("decrease");
  24.  
  25.             if (swap == true)
  26.             {
  27.                 string[] positions = checker.Split();
  28.                 int pos1 = int.Parse(positions[1]);
  29.                 int pos2 = int.Parse(positions[2]);
  30.  
  31.                 temp = input[pos1];
  32.                 input[pos1] = input[pos2];
  33.                 input[pos2] = temp;
  34.             }
  35.             else if (multiply == true)
  36.             {
  37.                 string[] positions = checker.Split();
  38.                 int pos1 = int.Parse(positions[1]);
  39.                 int pos2 = int.Parse(positions[2]);
  40.  
  41.                 input[pos1] *= input[pos2];
  42.             }
  43.             else if (decrease == true)
  44.             {
  45.                 input = Array.ConvertAll(input, x => x - 1);
  46.             }
  47.             else if (chck == true)
  48.             {
  49.                 chck = true;
  50.                 break;
  51.             }
  52.             checker = Console.ReadLine();
  53.         }
  54.  
  55.         //Output
  56.         Console.WriteLine(string.Join(", ", input));
  57.  
  58.     }
  59. }
Add Comment
Please, Sign In to add comment