Teo_Yanchev

Lists - ListManipulationBasics - C# Fundamentals

Sep 13th, 2020
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _6.ListManipulationBasics
  6. {
  7. class Program
  8. {
  9. static void Main(string[] args)
  10. {
  11. List<int> numbers = Console.ReadLine()
  12. .Split()
  13. .Select(int.Parse)
  14. .ToList();
  15.  
  16. List<string> command = Console.ReadLine()
  17. .Split(" ")
  18. .ToList();
  19. while (command[0] != "end")
  20. {
  21. string realCommand = command[0];
  22. int number = int.Parse(command[1]);
  23.  
  24.  
  25. if (realCommand == "Add")
  26. {
  27. numbers.Add(number);
  28. }
  29.  
  30. else if (realCommand == "Remove")
  31. {
  32. numbers.Remove(number);
  33. }
  34.  
  35. else if (realCommand == "RemoveAt")
  36. {
  37. // !!NB!! ** INDEX == number ** !!NB!!
  38. numbers.RemoveAt(number);
  39. }
  40.  
  41. else if (command.Count == 3)
  42. {
  43. int index = int.Parse(command[2]);
  44.  
  45. if (realCommand == "Insert")
  46. {
  47. numbers.Insert(index, number);
  48. }
  49. }
  50.  
  51. command = Console.ReadLine()
  52. .Split()
  53. .ToList();
  54.  
  55. }
  56.  
  57. Console.WriteLine(string.Join(" ", numbers));
  58. }
  59. }
  60. }
  61.  
Advertisement
Add Comment
Please, Sign In to add comment