Advertisement
Guest User

2. Change List

a guest
Oct 19th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace ListsEx
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11.  
  12. List<int> input = new List<int>(Console.ReadLine().Split(" ").Select(int.Parse).ToList());
  13.  
  14.  
  15. while (true)
  16. {
  17. var line = Console.ReadLine();
  18. if (line == "end")
  19. {
  20. break;
  21. }
  22.  
  23. string[] linecommand = line.Split(" ");
  24.  
  25. switch (linecommand[0])
  26. {
  27. case "Delete":
  28. int number = int.Parse(linecommand[1]);
  29. input.Remove(number);
  30. break;
  31.  
  32. case "Insert":
  33. int element = int.Parse(linecommand[1]);
  34. int position = int.Parse(linecommand[2]);
  35. input.Insert(position, element);
  36. break;
  37.  
  38. }
  39. }
  40. Console.WriteLine(string.Join(" ", input));
  41. }
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement