NastySwipy

Arrays & Methods - More Exercises - 02. Manipulate Array

Apr 9th, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.20 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace _05b__Arrays_Exercises
  5. {
  6.     class Arrays_Exercises
  7.     {
  8.         static void Main(string[] args)
  9.         {
  10.             string[] arr = Console.ReadLine().Split(' ').ToArray();
  11.             int numCommands = int.Parse(Console.ReadLine());
  12.             string[] commands = new string[numCommands];
  13.  
  14.             for (int i = 0; i < numCommands; i++)
  15.             {
  16.                 commands[i] = Console.ReadLine();
  17.                    
  18.             }
  19.  
  20.             for (int j = 0; j < numCommands; j++)
  21.             {
  22.                 if (commands[j] == "Distinct")
  23.                 {
  24.                     arr = arr.Distinct().ToArray();
  25.                 }
  26.                 if (commands[j] == "Reverse")
  27.                 {
  28.                     arr = arr.Reverse().ToArray();
  29.                 }
  30.                 if (commands[j].Split(' ').First() == "Replace")
  31.                 {
  32.                     int replace = int.Parse(commands[j].Split(' ')[1]);
  33.                     arr[replace] = arr[replace].Replace(arr[replace], commands[j].Split(' ')[2]);
  34.                 }
  35.             }            
  36.             Console.WriteLine(string.Join(", ", arr));
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment