Advertisement
silvana1303

task planner

Jun 16th, 2020
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.25 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Linq;
  5. using System.Threading;
  6.  
  7. namespace ConsoleApp1
  8. {
  9.     class Exam
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             List<int> tasks = Console.ReadLine().Split().Select(int.Parse).ToList();
  14.  
  15.             string[] command = Console.ReadLine().Split().ToArray();
  16.  
  17.             while (command[0] != "End")
  18.             {
  19.                 if (command[0] == "Complete")
  20.                 {
  21.                     Completed(tasks, command);
  22.                 }
  23.                 if (command[0] == "Change")
  24.                 {
  25.                     Change(tasks, command);
  26.                 }
  27.                 if (command[0] == "Drop")
  28.                 {
  29.                     Drop(tasks, command);
  30.                 }
  31.                 if (command[1] == "Completed")
  32.                 {
  33.                     Completed(tasks);
  34.                 }
  35.                 if (command[1] == "Incompleted")
  36.                 {
  37.                     Incompleted(tasks);
  38.                 }
  39.                 if (command[1] == "Dropped")
  40.                 {
  41.                     Dropped(tasks);
  42.                 }
  43.  
  44.                 command = Console.ReadLine().Split().ToArray();
  45.             }
  46.  
  47.             tasks.RemoveAll(x => x <= 0);
  48.  
  49.             Console.WriteLine(string.Join(" ", tasks));
  50.         }
  51.  
  52.         private static void Completed(List<int> tasks, string[] command)
  53.         {
  54.             int index = int.Parse(command[1]);
  55.             if (index >= 0 && index < tasks.Count)
  56.             {
  57.                 tasks[index] = 0;
  58.             }
  59.         }
  60.  
  61.         private static void Change(List<int> tasks, string[] command)
  62.         {
  63.             int index = int.Parse(command[1]);
  64.             int time = int.Parse(command[2]);
  65.             if (index >= 0 && index < tasks.Count && (time >= 1 && time <= 5))
  66.             {
  67.                 if (tasks[index] > 0)
  68.                 {
  69.                     tasks[index] = time;
  70.                 }
  71.                  
  72.             }
  73.         }
  74.  
  75.         private static void Drop(List<int> tasks, string[] command)
  76.         {
  77.             int index = int.Parse(command[1]);
  78.             if (index >= 0 && index < tasks.Count)
  79.             {
  80.                 tasks[index] = -1;
  81.             }
  82.         }
  83.  
  84.         private static void Completed(List<int> tasks)
  85.         {
  86.             int count = 0;
  87.             foreach (var item in tasks)
  88.             {
  89.                 if (item == 0)
  90.                 {
  91.                     count++;
  92.                 }
  93.             }
  94.  
  95.             Console.WriteLine(count);
  96.         }
  97.  
  98.         private static void Incompleted(List<int> tasks)
  99.         {
  100.             int count = 0;
  101.             foreach (var item in tasks)
  102.             {
  103.                 if (item > 0)
  104.                 {
  105.                     count++;
  106.                 }
  107.             }
  108.  
  109.             Console.WriteLine(count);
  110.         }
  111.  
  112.         private static void Dropped(List<int> tasks)
  113.         {
  114.             int count = 0;
  115.             foreach (var item in tasks)
  116.             {
  117.                 if (item == -1)
  118.                 {
  119.                     count++;
  120.                 }
  121.             }
  122.  
  123.             Console.WriteLine(count);
  124.         }
  125.     }
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement