Advertisement
Guest User

Array manipulations

a guest
Mar 19th, 2019
920
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.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp1
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string[] arr = Console.ReadLine().Split();
  14.             int n = int.Parse(Console.ReadLine());
  15.  
  16.             while(n-- > 0)
  17.             {
  18.                 string[] command = Console.ReadLine().Split();
  19.                 switch (command[0].ToLower())
  20.                 {
  21.                     case "reverse":
  22.                         Array.Reverse(arr);
  23.                         break;
  24.                     case "distinct":
  25.                         arr = arr.Distinct().ToArray();
  26.                         break;
  27.                     case "replace":
  28.                         int index = int.Parse(command[1]);
  29.                         string newWord = command[2];
  30.                         arr[index] = newWord;
  31.                         break;
  32.                 }
  33.             }
  34.  
  35.             Console.WriteLine(string.Join(", ", arr));
  36.         }
  37.     }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement