svephoto

Scheduling [C#]

Jul 21st, 2021 (edited)
466
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.41 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace Scheduling
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             Stack<int> tasks = new Stack<int>(Console.ReadLine()
  12.                 .Split(new[] { ", " }, StringSplitOptions.RemoveEmptyEntries)
  13.                 .Select(int.Parse)
  14.                 .ToArray());
  15.  
  16.             Queue<int> threads = new Queue<int>(Console.ReadLine()
  17.                 .Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries)
  18.                 .Select(int.Parse)
  19.                 .ToArray());
  20.  
  21.             int taskToBeKilled = int.Parse(Console.ReadLine());
  22.  
  23.             while (threads.Count != 0 && tasks.Count != 0)
  24.             {
  25.                 if (tasks.Peek() == taskToBeKilled)
  26.                 {
  27.                     Console.WriteLine($"Thread with value {threads.Peek()} killed task {taskToBeKilled}");
  28.  
  29.                     foreach (var currentThread in threads)
  30.                     {
  31.                         Console.Write(currentThread + " ");
  32.                     }
  33.  
  34.                     break;
  35.                 }
  36.  
  37.                 if (threads.Peek() >= tasks.Peek())
  38.                 {
  39.                     threads.Dequeue();
  40.                     tasks.Pop();
  41.                 }
  42.                 else
  43.                 {
  44.                     threads.Dequeue();
  45.                 }
  46.             }
  47.         }
  48.     }
  49. }
  50.  
Add Comment
Please, Sign In to add comment