Advertisement
Radost09

ArrayModifier

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