Advertisement
YavorJS

Array Modifier

Sep 12th, 2016
250
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 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.Array_Modifier
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. long[] numbers = Console.ReadLine().Split().Select(long.Parse).ToArray();
  14. string[] commands = Console.ReadLine().Split().ToArray();
  15.  
  16.  
  17. while (commands[0] != "end")
  18. {
  19. string command = commands[0];
  20. int index1 = 0;
  21. int index2 = 0;
  22. if (commands.Length > 1)
  23. {
  24. index1 = int.Parse(commands[1]);
  25. index2 = int.Parse(commands[2]);
  26. }
  27. if (command == "swap") swap(numbers, index1, index2);
  28. else if (command == "multiply") multiply(numbers, index1, index2);
  29. else if (command == "decrease") decrease(numbers);
  30. commands = Console.ReadLine().Split().ToArray();
  31. }
  32.  
  33. Console.WriteLine(string.Join(", ", numbers));
  34. }
  35.  
  36. private static void decrease(long[] numbers)
  37. {
  38. for (int num = 0; num < numbers.Length; num++)
  39. {
  40. numbers[num] = numbers[num] - 1;
  41. }
  42. }
  43.  
  44. private static void multiply(long[] numbers, int index1, int index2)
  45. {
  46. long temp = numbers[index1] * numbers[index2];
  47. numbers[index1] = temp;
  48. }
  49.  
  50. private static void swap(long[] numbers, int index1, int index2)
  51. {
  52. long temp1 = numbers[index1];
  53. long temp2 = numbers[index2];
  54. numbers[index1] = temp2;
  55. numbers[index2] = temp1;
  56. }
  57. }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement