Advertisement
peshopbs2

Untitled

Feb 28th, 2020
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.25 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 ListManipulation
  8. {
  9. class Program
  10. {
  11. private static List<int> numbers;
  12. static void Main(string[] args)
  13. {
  14. numbers = Console.ReadLine()
  15. .Split(' ')
  16. .Select(int.Parse)
  17. .ToList();
  18.  
  19. string command = Console.ReadLine();
  20. while (command != "End")
  21. {
  22. ProcessCommand(command);
  23. command = Console.ReadLine();
  24. }
  25. }
  26.  
  27. static void ProcessCommand(string command)
  28. {
  29. string[] commandInfo = command.Split(' ');
  30.  
  31. string commandName = commandInfo[0];
  32.  
  33.  
  34. switch (commandName)
  35. {
  36. case "add":
  37. Add(commandInfo);
  38. break;
  39. case "addMany":
  40. AddMany(commandInfo);
  41. break;
  42. case "contains":
  43. Contains(commandInfo);
  44. break;
  45. case "remove":
  46. Remove(commandInfo);
  47. break;
  48. case "shift":
  49. Shift(commandInfo);
  50. break;
  51. case "sumPairs":
  52. SumPairs(commandInfo);
  53. break;
  54. case "print":
  55. Print(commandInfo);
  56. break;
  57. default:
  58. break;
  59. }
  60. }
  61.  
  62. public static void Add(string[] commandInfo)
  63. {
  64. int index = int.Parse(commandInfo[1]);
  65. int value = int.Parse(commandInfo[2]);
  66.  
  67. numbers.Insert(index, value);
  68. }
  69.  
  70. public static void AddMany(string[] commandInfo)
  71. {
  72. //addMany 2 38 48 2983 58 923
  73. int[] numbersToAdd = commandInfo
  74. .Skip(1) //skip the command name
  75. .Select(int.Parse)
  76. .ToArray();
  77.  
  78. numbers.AddRange(numbersToAdd);
  79. }
  80.  
  81. public static void Contains(string[] commandInfo)
  82. {
  83. int searchedItem = int.Parse(commandInfo[1]);
  84. int foundIndex = numbers.IndexOf(searchedItem);
  85.  
  86. Console.WriteLine(foundIndex);
  87. }
  88.  
  89. public static void Remove(string[] commandInfo)
  90. {
  91. int index = int.Parse(commandInfo[1]);
  92. numbers.RemoveAt(index);
  93. }
  94.  
  95. public static void Shift(string[] commandInfo)
  96. {
  97. int rotationElements = int.Parse(commandInfo[1]);
  98.  
  99. List<int> startList = numbers
  100. .Skip(rotationElements)
  101. .ToList();
  102.  
  103. List<int> endList = numbers
  104. .Take(rotationElements)
  105. .ToList();
  106.  
  107. startList.AddRange(endList);
  108. numbers = startList;
  109. }
  110.  
  111. public static void SumPairs(string[] commandInfo)
  112. {
  113.  
  114. }
  115.  
  116. public static void Print(string[] commandInfo)
  117. {
  118. Console.WriteLine(string.Join(" ", numbers));
  119. }
  120. }
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement