Advertisement
sivancheva

SafeManipulationCorrected

Aug 18th, 2017
274
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.41 KB | None | 0 0
  1. /*
  2. * Created by SharpDevelop.
  3. * User: savina.ivancheva
  4. * Date: 18.08.2017
  5. * Time: 09:18
  6. *
  7. * To change this template use Tools | Options | Coding | Edit Standard Headers.
  8. */
  9. using System;
  10. using System.Linq;
  11.  
  12. namespace SafeManipulation
  13. {
  14. class Program
  15. {
  16. public static void Main(string[] args)
  17. {
  18. var input = Console.ReadLine().Split(' ');
  19. var manipulatedArray = input;
  20. int lengthArr = manipulatedArray.Length;
  21.  
  22.  
  23. string[] command = Console.ReadLine().Split(' ');
  24.  
  25.  
  26. while (command[0] != "END")
  27. {
  28. string action = command[0];
  29.  
  30.  
  31. if (action == "Reverse")
  32. {
  33. manipulatedArray = manipulatedArray.Reverse().ToArray();
  34. }
  35. else if (action == "Distinct")
  36. {
  37.  
  38. manipulatedArray = manipulatedArray.Distinct().ToArray();
  39. lengthArr = manipulatedArray.Count(s => s != null);
  40.  
  41. }
  42. else if (action == "Replace")
  43.  
  44. {
  45. int index = int.Parse(command[1]);
  46. string wordToChange = command[2];
  47.  
  48. if (index > lengthArr-1 || (index < 0))
  49. {
  50. Console.WriteLine("Invalid input!");
  51. }
  52. else
  53. {
  54. manipulatedArray[index] = wordToChange;
  55. }
  56. }
  57. else
  58. {
  59. Console.WriteLine("Invalid input!");
  60. }
  61. command = Console.ReadLine().Split(' ').ToArray();
  62. }
  63.  
  64. Console.WriteLine(String.Join(", ", manipulatedArray));
  65.  
  66. }
  67. }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement