Advertisement
Guest User

02. Change List

a guest
Feb 22nd, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.65 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6.  
  7. namespace ConsoleApp7
  8. {
  9. class Program
  10. {
  11.  
  12. static void Main(string[] args)
  13. {
  14.  
  15. List<int> inputList = Console.ReadLine().Split().Select(int.Parse).ToList();
  16.  
  17. string command = Console.ReadLine();
  18.  
  19. while (command != "Odd" && command != "Even")
  20. {
  21. string[] tokens = command.Split();
  22.  
  23. if (tokens[0] == "Delete")
  24. {
  25. int deleteNum = int.Parse(tokens[1]);
  26. inputList.RemoveAll(item => item == deleteNum);
  27. }
  28. else if (tokens[0] == "Insert")
  29. {
  30. int element = int.Parse(tokens[1]);
  31. int index = int.Parse(tokens[2]);
  32. inputList.Insert(index, element);
  33. }
  34.  
  35. command = Console.ReadLine();
  36. }
  37.  
  38. if (command == "Odd")
  39. {
  40. for (int i = 0; i < inputList.Count; i++)
  41. {
  42. if (inputList[i] % 2 != 0)
  43. {
  44. Console.Write(inputList[i] + " ");
  45. }
  46. }
  47. }
  48. else if (command == "Even")
  49. {
  50. for (int i = 0; i < inputList.Count; i++)
  51. {
  52. if (inputList[i] % 2 == 0)
  53. {
  54. Console.Write(inputList[i] + " ");
  55. }
  56. }
  57. }
  58.  
  59. }
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement