Advertisement
sivancheva

SafeManipulation

Aug 18th, 2017
201
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3.  
  4. namespace SafeManipulation
  5. {
  6. class Program
  7. {
  8. public static void Main(string[] args)
  9. {
  10. var input = Console.ReadLine().Split(' ');
  11. var manipulatedArray = input;
  12. int lengthArr = manipulatedArray.Length;
  13.  
  14.  
  15. string[] command = Console.ReadLine().Split(' ');
  16.  
  17.  
  18. while (command[0] != "END")
  19. {
  20. string action = command[0];
  21.  
  22.  
  23. if (action == "Reverse")
  24. {
  25. manipulatedArray = manipulatedArray.Reverse().ToArray();
  26. }
  27. else if (action == "Distinct")
  28. {
  29.  
  30. manipulatedArray = manipulatedArray.Distinct().ToArray();
  31. lengthArr = manipulatedArray.Count(s => s != null);
  32.  
  33. }
  34. else
  35. {
  36. int index = int.Parse(command[1]);
  37. string wordToChange = command[2];
  38.  
  39. if (index > lengthArr-1 || (index < 0))
  40. {
  41. Console.WriteLine("Invalid input!");
  42. }
  43. else
  44. {
  45. manipulatedArray[index] = wordToChange;
  46. }
  47. }
  48.  
  49. command = Console.ReadLine().Split(' ').ToArray();
  50. }
  51.  
  52. Console.WriteLine(String.Join(", ", manipulatedArray));
  53.  
  54. }
  55. }
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement