Advertisement
Terziyski

Problem 3. Safe Manipulation

Jun 15th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.91 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 Problem_2.Manipulate_Array
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             string[] arr = Console.ReadLine().Split(' ').ToArray();
  14.  
  15.             var changeArray = arr;
  16.             var count = 0;
  17.  
  18.             while (true)
  19.             {
  20.                 string commands = Console.ReadLine();
  21.  
  22.                 for (int i = 0; i < arr.Length - 1 ; i++)
  23.                 {
  24.                     if (arr[i] == arr[i + 1])
  25.                     {
  26.                         count++;
  27.  
  28.                     }
  29.                 }
  30.  
  31.                 if (commands == "Distinct")
  32.                 {
  33.                     if (count > 0)
  34.                     {
  35.                         changeArray = changeArray.Distinct().ToArray();
  36.  
  37.                     }
  38.                     else
  39.                     {
  40.                         Console.WriteLine("Invalid input!");
  41.                     }
  42.  
  43.                 }
  44.                 if (commands == "Reverse")
  45.                 {
  46.                     Array.Reverse(changeArray);
  47.                 }
  48.                 if (commands != "Distinct" && commands != "Reverse" && commands != "END")
  49.                 {
  50.                     string[] replace = commands.Split(' ').ToArray();
  51.                     int temp = int.Parse(replace[1]);
  52.  
  53.                     if (temp >= changeArray.Length || temp < 0 )
  54.                     {
  55.                         Console.WriteLine("Invalid input!");
  56.                         continue;
  57.                     }
  58.                     changeArray[int.Parse(replace[1])] = replace[2];
  59.                 }
  60.                 if (commands == "END")
  61.                 {
  62.                     break;
  63.                 }
  64.             }
  65.  
  66.             Console.WriteLine(string.Join(", ", changeArray));
  67.  
  68.         }
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement