Advertisement
knoteva

Untitled

Aug 4th, 2019
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.19 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace _02._Problem
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             var list = Console.ReadLine()
  12.                 .Split()
  13.                 .Where(x => !string.IsNullOrWhiteSpace(x))
  14.                 .Select(int.Parse)
  15.                 .ToList();
  16.             string input = Console.ReadLine();
  17.             while (input != "End")
  18.             {
  19.                 string[] tokens = input.Split();
  20.                 string command = tokens[0];
  21.                 if (command == "Complete")
  22.                 {
  23.                     int indexToFind = int.Parse(tokens[1]);
  24.                     if (indexToFind >= 0 && indexToFind < list.Count)
  25.                     {
  26.                         int completedTask = list.ElementAt(indexToFind);
  27.                         list[completedTask] = 0;
  28.                     }
  29.                 }
  30.                 else if (command == "Change")
  31.                 {
  32.                     int indexToLookFor = int.Parse(tokens[1]);
  33.                     int timeChange = int.Parse(tokens[2]);
  34.                     if (indexToLookFor >= 0 && indexToLookFor < list.Count)
  35.                     {
  36.                         //int timeToBeReplaced = list.ElementAt(indexToLookFor);
  37.                         list[indexToLookFor] = timeChange; // не трябва да е timeToBeReplaced
  38.                     }
  39.                 }
  40.                 else if (command == "Drop")
  41.                 {
  42.                     int indexToDrop = int.Parse(tokens[1]);
  43.                     if (indexToDrop >= 0 && indexToDrop < list.Count)
  44.                     {
  45.                         //int itemToDrop = list.ElementAt(indexToDrop);
  46.                         list[indexToDrop] = -1; // не трябва да е itemToDrop
  47.                     }
  48.                 }
  49.                 else if (command == "Count") // tokens[0] ти е само Count
  50.                 {
  51.                     int counter = 0;
  52.                     foreach (var completed in list.Where(x => x == 0))
  53.                     {
  54.                         counter++;
  55.                     }
  56.                     Console.WriteLine(counter);
  57.  
  58.                 }
  59.                 else if (command == "Count Incomplete") //
  60.                 {
  61.                     int counter = 0;
  62.                     foreach (var incomplete in list.Where(x => x > 0))
  63.                     {
  64.                         counter++;
  65.                     }
  66.                     Console.WriteLine(counter);
  67.                 }
  68.                 else if (command == "Count Dropped")
  69.                 {
  70.                     int counter = 0;
  71.                     foreach (var dropped in list.Where(x => x < 0))
  72.                     {
  73.                         counter++;
  74.                     }
  75.                     Console.WriteLine(counter);
  76.                 }
  77.  
  78.                 input = Console.ReadLine();
  79.             }
  80.            // foreach (var incompleteTask in list.Where(x => x > 0)) // не ти трябва  след като ще ползваш string.Join
  81.             //{
  82.                 Console.WriteLine(string.Join(" ", list.Where(x => x > 0)));
  83.             //}
  84.         }
  85.     }
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement