Advertisement
boykopk

Untitled

Oct 17th, 2017
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.63 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 _10.Array_Manipulator
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. List<long> list = Console.ReadLine().Split(' ').Select(long.Parse).ToList();
  14. string command = Console.ReadLine();
  15.  
  16. while(command != "print")
  17. {
  18. string[] tokens = command.Split(' ');
  19. switch(tokens[0])
  20. {
  21. case "add":
  22. int index = int.Parse(tokens[1]);
  23. long element = long.Parse(tokens[2]);
  24. list.Insert(index, element);
  25. break;
  26. case "addMany":
  27. int index2 = int.Parse(tokens[1]);
  28. List<long> elementsToAdd = tokens.Skip(2).Select(long.Parse).ToList();
  29. list.InsertRange(index2, elementsToAdd);
  30. break;
  31. case "contains":
  32. long element2 = long.Parse(tokens[1]);
  33. Console.WriteLine(list.IndexOf(element2));
  34. break;
  35. case "remove":
  36. int index3 = int.Parse(tokens[1]);
  37. list.RemoveAt(index3);
  38. break;
  39. case "shift":
  40. int positions = int.Parse(tokens[1]);
  41. for(int i = 0; i<positions; i++)
  42. {
  43. long lastElement = list[0];
  44. for(int j=0; j<list.Count -1; j++)
  45. {
  46. list[j] = list[j + 1];
  47. }
  48. list[list.Count - 1] = lastElement;
  49. }
  50. break;
  51. case "sumPairs":
  52. List<long> newList = new List<long>();
  53. for (int i=0; i<list.Count - 1; i+=2)
  54. {
  55. newList.Add(list[i] + list[i + 1]);
  56. }
  57. if(list.Count%2 == 1)
  58. {
  59. newList.Add(list[list.Count - 1]);
  60. }
  61. list = newList;
  62. break;
  63. }
  64.  
  65. command = Console.ReadLine();
  66. }
  67.  
  68. Console.WriteLine("[" + string.Join(", ", list) + "]");
  69. }
  70. }
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement