Advertisement
Guest User

Untitled

a guest
Aug 20th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _05.Array_Manipulator
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. List<int> list = Console.ReadLine().Split().Select(int.Parse).ToList();
  12. string input = Console.ReadLine();
  13. string[] command = input.Split().ToArray();
  14. string commandword = command[0];
  15.  
  16. while (commandword!="print")
  17. {
  18.  
  19. if (commandword=="add")
  20. {
  21. int index = int.Parse(command[1]);
  22. int value = int.Parse(command[2]);
  23. list.Insert(index, value);
  24. }
  25. else if (commandword == "addMany")
  26. {
  27. int index = int.Parse(command[1]);
  28. int[] parsed = new int[command.Length-2];
  29. for (int i = 2; i < command.Length; i++)
  30. {
  31. parsed[i-2] = int.Parse(command[i]);
  32. }
  33. list.InsertRange(index, parsed);
  34. }
  35. else if (commandword=="contains")
  36. {
  37. int magic = int.Parse(command[1]);
  38. for (int i = 0; i < list.Count; i++)
  39. {
  40. if (list[i] == magic)
  41. {
  42. Console.WriteLine(i);break;
  43. }
  44. if (i==list.Count-1)
  45. {
  46. Console.WriteLine(-1);
  47. }
  48. }
  49. }
  50. else if (commandword == "remove")
  51. {
  52. int index = int.Parse(command[1]);
  53. list.RemoveAt(index);
  54. }
  55. else if (commandword == "shift")
  56. {
  57. int positions = int.Parse(command[1]);
  58. for (int j = 0; j < positions; j++)
  59. {
  60. int temp = list[0];
  61. for (int i = 0; i < list.Count - 1; i++)
  62. {
  63. list[i] = list[i + 1];
  64. }
  65. list[list.Count - 1] = temp;
  66. }
  67.  
  68.  
  69. }
  70. else if (commandword == "sumPairs")
  71. {
  72. for (int i = list.Count-1; i >0; i-=2)
  73. {
  74. list[i-1] =list[i]+ list[i- 1];
  75. list.RemoveAt(i);
  76. }
  77. }
  78.  
  79. input = Console.ReadLine();
  80. command = input.Split().ToArray();
  81. commandword = command[0];
  82. }
  83. Console.Write("[");
  84. Console.Write(string.Join(", ",list));
  85. Console.Write("]");
  86. }
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement