Advertisement
tochka

Untitled

Oct 14th, 2017
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 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 ConsoleApp95
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. List<int> numbers = Console.ReadLine()
  14. .Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries)
  15. .Select(int.Parse)
  16. .ToList();
  17.  
  18. string[] commands = Console.ReadLine().Split(' ');
  19.  
  20. while (commands[0] != "print")
  21. {
  22. if (commands[0] == "add")
  23. {
  24. int index = int.Parse(commands[1]);
  25. int element = int.Parse(commands[2]);
  26. numbers.Insert(index, element);
  27. }
  28. if (commands[0] == "addMany")
  29. {
  30. int index = int.Parse(commands[1]);
  31.  
  32. for (int i = commands.Length -1; i >= 2; i--)
  33. {
  34. int element = int.Parse(commands[i]);
  35. numbers.Insert(index, element);
  36. }
  37. }
  38. if (commands[0] == "contains")
  39. {
  40. int element = int.Parse(commands[1]);
  41. if(numbers.Contains(element))
  42. {
  43. Console.WriteLine("{0}", numbers.IndexOf(element));
  44. }
  45. else
  46. {
  47. Console.WriteLine("-1");
  48. }
  49. }
  50. if (commands[0] == "remove")
  51. {
  52. int index = int.Parse(commands[1]);
  53. numbers.RemoveAt(index);
  54. }
  55. if (commands[0] == "shift")
  56. {
  57. for (int i = 0; i < int.Parse(commands[1]) % numbers.Count; i++)
  58. {
  59. numbers.Add(numbers[0]);
  60. numbers.RemoveAt(0);
  61. }
  62.  
  63. }
  64. if (commands[0] == "sumPairs")
  65. {
  66. List<int> sum = new List<int>();
  67. while (numbers.Count >= 2)
  68. {
  69. sum.Add(numbers[0] + numbers[1]);
  70. numbers.RemoveAt(0);
  71. numbers.RemoveAt(0);
  72. }
  73. if (numbers.Count == 1) sum.Add(numbers[0]);
  74. numbers = sum;
  75.  
  76. }
  77.  
  78.  
  79. commands = Console.ReadLine().Split(' ');
  80. }
  81.  
  82. Console.WriteLine($"[{string.Join(", ", numbers)}]");
  83.  
  84.  
  85.  
  86. }
  87. }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement