Guest User

Untitled

a guest
Feb 23rd, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.92 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. namespace TaskPlanner
  5. {
  6. class Program
  7. {
  8. static int CountIncomplete(List<string> list)
  9. {
  10. int incompletedTasks = 0;
  11. for (int i = 0; i < list.Count ; i++)
  12. {
  13. if (list[i] != "0" && list[i] != "-1")
  14. {
  15. incompletedTasks++;
  16. }
  17. }
  18. return incompletedTasks;
  19. }
  20. static int CountCompleted(List<string> list)
  21. {
  22. int completedTasks = 0;
  23. for (int i = 0; i < list.Count ; i++)
  24. {
  25. if(list[i] == "0")
  26. {
  27. completedTasks++;
  28. }
  29. }
  30. return completedTasks;
  31. }
  32. static int CountDrop(List<string> list)
  33. {
  34. int dropElements = 0;
  35. for (int i = 0; i < list.Count; i++)
  36. {
  37. if (list[i] == "-1")
  38. {
  39. dropElements++;
  40. }
  41. }
  42. return dropElements;
  43. }
  44. static List<string> Drop(List<string> list, int index)
  45. {
  46. if (index >= 0 && index <= list.Count )
  47. {
  48. list.RemoveAt(index);
  49. list.Insert(index, "-1");
  50. }
  51. return list;
  52. }
  53. static List<string> Change(List<string> list, int index, string value)
  54. {
  55. if (index >= 0 && index <= list.Count )
  56. {
  57. list.RemoveAt(index);
  58. list.Insert(index, value);
  59. }
  60. return list;
  61. }
  62. static List<string> Complete(List<string> list, int index)
  63. {
  64. if (index >= 0 && index <= list.Count )
  65. {
  66. list.RemoveAt(index);
  67. list.Insert(index, "0");
  68. }
  69. return list;
  70. }
  71. static void Main()
  72. {
  73. List<string> taskList = Console.ReadLine().Split().ToList();
  74. string command = Console.ReadLine();
  75. while (command != "End")
  76. {
  77. string[] manipulation = command.Split().ToArray();
  78. switch (manipulation[0])
  79. {
  80. case "Complete":
  81. int index = int.Parse(manipulation[1]);
  82. taskList = Complete(taskList, index);
  83. break;
  84. case "Change":
  85. index = int.Parse(manipulation[1]);
  86. string value = manipulation[2];
  87. taskList = Change(taskList, index, value);
  88. break;
  89. case "Drop":
  90. index = int.Parse(manipulation[1]);
  91. taskList = Drop(taskList, index);
  92. break;
  93. default:
  94. case "Count":
  95. if (manipulation[1] == "Dropped")
  96. {
  97. Console.WriteLine(CountDrop(taskList));
  98. }
  99. else if (manipulation[1] == "Completed")
  100. {
  101. Console.WriteLine(CountCompleted(taskList));
  102. }
  103. else if (manipulation[1] == "Incomplete")
  104. {
  105. Console.WriteLine(CountIncomplete(taskList));
  106. }
  107. break;
  108. }
  109. command = Console.ReadLine();
  110. }
  111.  
  112. foreach (string item in taskList)
  113. {
  114. if (item != "0" && item != "-1")
  115. {
  116. Console.Write(item + " ");
  117. }
  118. }
  119. }
  120. }
  121. }
Add Comment
Please, Sign In to add comment