Advertisement
Guest User

05. ArrayManipulator

a guest
Oct 11th, 2017
172
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. using System.Security.Cryptography.X509Certificates;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7.  
  8. namespace _05.ArrayManipulator
  9. {
  10. class Program
  11. {
  12. static void Main(string[] args)
  13. {
  14. List<int> nums = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
  15. string[] command = Console.ReadLine().Split(' ').ToArray();
  16.  
  17. while (command[0] != "print")
  18. {
  19. if (command[0] == "add")
  20. {
  21. nums.Insert(int.Parse(command[1]), int.Parse(command[2]));
  22. }
  23. else if (command[0] == "addMany")
  24. {
  25. for (int i = command.Length - 1; i >= 2; i--)
  26. {
  27. nums.Insert(int.Parse(command[1]), int.Parse(command[i]));
  28. }
  29. }
  30. else if (command[0] == "contains")
  31. {
  32. if (nums.Contains(int.Parse(command[1])))
  33. {
  34. Console.WriteLine(nums.FindIndex(x => x == int.Parse(command[1])));
  35. }
  36. else Console.WriteLine("-1");
  37. }
  38. else if (command[0] == "remove") nums.RemoveAt(int.Parse(command[1]));
  39. else if (command[0] == "shift")
  40. {
  41. List<int> list = new List<int>();
  42. for (int i = 0; i < int.Parse(command[1]); i++)
  43. {
  44. list.Add(nums[0]);
  45. nums.Remove(nums[0]);
  46. }
  47. nums.AddRange(list);
  48. }
  49. else if (command[0] == "sumPairs")
  50. {
  51. for (int i = 0; i < nums.Count; i++)
  52. {
  53. if (i + 1 != nums.Count)
  54. {
  55. nums[i] += nums[i + 1];
  56. nums.RemoveAt(i + 1);
  57. }
  58. }
  59. }
  60. command = Console.ReadLine().Split(' ').ToArray();
  61. }
  62. Console.WriteLine("[" + string.Join(", ", nums) + "]");
  63.  
  64. }
  65. }
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement