Advertisement
MZlatev

Untitled

Oct 25th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _2._ChangeList
  6. {
  7. class ChangeList
  8. {
  9. static void Main()
  10. {
  11. List<int> numbers = Console.ReadLine()
  12. .Split(" ")
  13. .Select(int.Parse)
  14. .ToList();
  15.  
  16. string input;
  17.  
  18. while ((input = Console.ReadLine()) != "end")
  19. {
  20. string[] splitedInput = input
  21. .Split(" ");
  22.  
  23. string command = splitedInput[0];
  24. int number = int.Parse(splitedInput[1]);
  25.  
  26. if (command == "Delete")
  27. {
  28. //numbers.RemoveAll(x => x == number);
  29.  
  30. for (int i = 0; i < numbers.Count; i++)
  31. {
  32. if (number == numbers[i])
  33. {
  34. numbers.Remove(number);
  35. i--;
  36. }
  37. }
  38. }
  39.  
  40. else if (command == "Insert")
  41. {
  42. int position = int.Parse(splitedInput[2]);
  43.  
  44. numbers.Insert(position, number);
  45. }
  46. }
  47.  
  48. Console.WriteLine(string.Join(" ", numbers));
  49. }
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement