Advertisement
Guest User

Task Planner 90/100

a guest
Feb 24th, 2020
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.98 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Collections.Generic;
  4.  
  5. namespace Tasks_Planner
  6. {
  7.     class Program
  8.     {
  9.         static void Main()
  10.         {
  11.             var taskList = Console.ReadLine().Split().ToList();
  12.             string input = Console.ReadLine();
  13.  
  14.             while(input != "End")
  15.             {
  16.                 List<string> command = input.Split().ToList();
  17.                
  18.                 if (command[0] == "Complete" && IsIndexExist(taskList, command))
  19.                 {
  20.                     int taskIndex = int.Parse(command[1].ToString());
  21.                     taskList[taskIndex] = "0";
  22.                 }
  23.                 else if (command[0] == "Change" && IsIndexExist(taskList, command))
  24.                 {
  25.                     int taskIndex = int.Parse(command[1].ToString());
  26.                     taskList[taskIndex] = command[2];
  27.                 }
  28.                 else if (command[0] == "Drop" && IsIndexExist(taskList, command))
  29.                 {
  30.                     int taskIndex = int.Parse(command[1].ToString());
  31.                     taskList[taskIndex] = "-1";
  32.                 }
  33.                 else if(command[0] == "Count")
  34.                 {
  35.                     if (command[1] == "Completed")
  36.                     {
  37.                         int count = 0;
  38.                         foreach (var item in taskList.Where(i => i == "0"))
  39.                         {
  40.                             count++;
  41.                         }
  42.                         Console.WriteLine(count);
  43.                     }
  44.                     else if (command[1] == "Incomplete")
  45.                     {
  46.                         int count = 0;
  47.                         foreach (var item in taskList.Where(i => i != "0" && i != "-1"))
  48.                         {
  49.                             count++;                          
  50.                         }
  51.                         Console.WriteLine(count);
  52.  
  53.                     }
  54.                     else if (command[1] == "Dropped")
  55.                     {
  56.                         int count = 0;
  57.                         foreach (var item in taskList.Where(i => i == "-1"))
  58.                         {
  59.                             count++;
  60.                         }
  61.                         Console.WriteLine(count);
  62.                     }
  63.                 }
  64.                 input = Console.ReadLine();
  65.             }
  66.             List<string> newList = new List<string>();
  67.             foreach (var item in taskList.Where(i => i != "0" && i != "-1"))
  68.                 {
  69.                 newList.Add(item);
  70.             }
  71.             Console.WriteLine(string.Join(" ", newList));
  72.  
  73.         }
  74.         static bool IsIndexExist(List<string> taskList, List<string> command)
  75.         {
  76.             bool isIndexExist = false;
  77.             int index = int.Parse(command[1].ToString());
  78.             if (index >= 0 && index < taskList.Count)
  79.             {
  80.                 isIndexExist = true;
  81.             }
  82.             return isIndexExist;
  83.         }
  84.     }
  85. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement