Advertisement
MARINA_GREBENAROVA

Array Modifier

Mar 26th, 2023
682
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.48 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _02._Array_Modifier
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             int[] arr = Console.ReadLine()
  11.                 .Split(' ', StringSplitOptions.RemoveEmptyEntries)
  12.                 .Select(int.Parse)
  13.                 .ToArray();
  14.  
  15.             string command = Console.ReadLine();
  16.  
  17.             while (command != "end")
  18.             {
  19.  
  20.                 string[] cmd = command.Split(' ', StringSplitOptions.RemoveEmptyEntries).ToArray();
  21.                 string action = cmd[0];
  22.  
  23.                 if (action == "swap")
  24.                 {
  25.                     int index1 = int.Parse(cmd[1]);
  26.                     int index2 = int.Parse(cmd[2]);
  27.  
  28.                     int temp = arr[index1];
  29.                     arr[index1] = arr[index2];
  30.                     arr[index2] = temp;
  31.  
  32.                 }
  33.                 if (action == "multiply")
  34.                 {
  35.                     int index1 = int.Parse(cmd[1]);
  36.                     int index2 = int.Parse(cmd[2]);
  37.                     arr[index1] = arr[index1] * arr[index2];
  38.                 }
  39.                 if (action == "decrease")
  40.                 {
  41.                     for (int i = 0; i < arr.Length; i++)
  42.                     {
  43.                         arr[i]--;
  44.                     }
  45.                 }
  46.  
  47.                 command = Console.ReadLine();
  48.  
  49.             }
  50.  
  51.             Console.WriteLine(string.Join(", ", arr));
  52.         }
  53.     }
  54. }
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement