Advertisement
Guest User

Untitled

a guest
Jun 5th, 2018
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.15 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace arrayManipulator
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. List<int> input = Console.ReadLine()
  12. .Split()
  13. .Select(int.Parse)
  14. .ToList();
  15.  
  16. List<int> contains = new List<int>();
  17.  
  18. List<int> addMany = new List<int>();
  19.  
  20. while (true)
  21. {
  22. List<string> operations = Console.ReadLine()
  23. .Split()
  24. .ToList();
  25. if (operations[0] == "add")
  26. {
  27. input.Insert(int.Parse(operations[1]), int.Parse(operations[2]));
  28. }
  29. else if (operations[0] == "addMany")
  30. {
  31. for (int i = 2; i < operations.Count; i++)
  32. {
  33. addMany.Add(int.Parse(operations[i]));
  34. }
  35. input.InsertRange(int.Parse(operations[1]), addMany);
  36. }
  37. else if (operations[0] == "contains")
  38. {
  39. Console.WriteLine(input.IndexOf(int.Parse(operations[1])));
  40. }
  41. else if (operations[0] == "remove")
  42. {
  43. input.RemoveAt(int.Parse(operations[1]));
  44. }
  45. else if (operations[0] == "shift")
  46. {
  47. int first = input[0];
  48. input.RemoveAt(0);
  49. input.Add(first);
  50.  
  51. }
  52. else if(operations[0] == "sumPairs")
  53. {
  54. for (int i = 0; i < input.Count - 1; i++)
  55. {
  56. input[i] += input[i + 1];
  57. input.RemoveAt(i + 1);
  58. }
  59. }
  60. else if (operations[0] == "print")
  61. {
  62. break;
  63. }
  64.  
  65.  
  66. }
  67. Console.WriteLine($"[{string.Join(", ", input)}]");
  68. }
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement