Advertisement
kalitarix

Manipulate array

Aug 17th, 2018
242
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.07 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace ManipulateArray
  5. {
  6.     class Program
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string[] array = Console.ReadLine().Split();
  11.             int numberOfCommands = int.Parse(Console.ReadLine());
  12.  
  13.             for (int currentCommand = 0; currentCommand < numberOfCommands; currentCommand++)
  14.             {
  15.                 string[] commands = Console.ReadLine().Split();
  16.                 string command = commands[0];
  17.  
  18.                 if (command == "Reverse")
  19.                 {
  20.                     Array.Reverse(array);
  21.                 }
  22.                 else if (command == "Distinct")
  23.                 {
  24.                     array = array.Distinct().ToArray();
  25.                 }
  26.                 else if (command == "Replace")
  27.                 {
  28.                     int index = int.Parse(commands[1]);
  29.                     string newWord = commands[2];
  30.  
  31.                     array[index] = newWord;
  32.                 }
  33.             }
  34.  
  35.             Console.WriteLine(string.Join(", ", array));
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement