Advertisement
Guest User

Untitled

a guest
Jun 16th, 2017
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.51 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace Lab1RemoveNegatxvesAndReverse
  5. {
  6. class Program
  7. {
  8. public static List<int> nums = new List<int>();
  9. static void Main(string[] args)
  10. {
  11. nums = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
  12. string[] command = Console.ReadLine().Split(' ').ToArray();
  13. while (command[0] != "print")
  14. {
  15. switch (command[0])
  16. {
  17. case "add":
  18. nums.Insert(int.Parse(command[1]), int.Parse(command[2]));
  19. break;
  20. case "addMany":
  21. int pos = int.Parse(command[1]);
  22. for (int i = 2; i < command.Length; i++)
  23. {
  24. nums.Insert(pos, int.Parse(command[i]));
  25. pos++;
  26. }
  27. break;
  28. case "contains":
  29. int index = nums.IndexOf(int.Parse(command[1]));
  30. Console.WriteLine(index);
  31. break;
  32. case "remove":
  33. nums.RemoveAt(int.Parse(command[1]));
  34. break;
  35. case "shift":
  36. int positionsToMove = int.Parse(command[1]);
  37. for (int j = 0; j < positionsToMove; j++)
  38. {
  39. int firstElement = nums[0];
  40. for (int i = 1; i < nums.Count; i++)
  41. {
  42. nums[i - 1] = nums[i];
  43. }
  44. nums[nums.Count - 1] = firstElement;
  45. }
  46. break;
  47. case "sumPairs":
  48. for (int i = 0; i < nums.Count - 1; i += 2)
  49. {
  50. nums[i] += nums[i + 1];
  51. nums[i + 1] = -1;
  52. }
  53. nums.RemoveAll(x => x ==-1);
  54. break;
  55. default:
  56. Console.WriteLine("Incorrect input. Please write add, addMany, contains, shift or sumPairs");
  57. break;
  58. }
  59. command = Console.ReadLine().Split(' ').ToArray();
  60.  
  61. }
  62. Console.WriteLine("[" + string.Join(", ", nums) + "]");
  63. }
  64. }
  65. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement