Advertisement
Guest User

Untitled

a guest
Jun 5th, 2018
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.30 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. for (int i = 0; i < int.Parse(operations[1]); i++)
  48. {
  49. int first = input[0];
  50. input.RemoveAt(0);
  51. input.Add(first);
  52. }
  53. }
  54. else if(operations[0] == "sumPairs")
  55. {
  56. for (int i = 0; i < input.Count - 1; i++)
  57. {
  58. input[i] += input[i + 1];
  59. input.RemoveAt(i + 1);
  60. }
  61. }
  62. else if (operations[0] == "print")
  63. {
  64. break;
  65. }
  66.  
  67.  
  68. }
  69. Console.WriteLine($"[{string.Join(", ", input)}]");
  70. }
  71. }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement