Advertisement
fbinnzhivko

Untitled

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