Advertisement
silvana1303

Scheduling

Oct 25th, 2020 (edited)
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.15 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Linq;
  5. using System.Text;
  6.  
  7. namespace BookWorm
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             int[] stack = Console.ReadLine().Split(",").Select(int.Parse).ToArray();
  14.             int[] queue = Console.ReadLine().Split().Select(int.Parse).ToArray();
  15.             int kill = int.Parse(Console.ReadLine());
  16.  
  17.             Stack<int> task = new Stack<int>(stack);
  18.             Queue<int> thread = new Queue<int>(queue);
  19.  
  20.             while (task.Any() && thread.Any())
  21.             {
  22.                 if (task.Peek() == kill)
  23.                 {
  24.                     break;
  25.                 }
  26.  
  27.                 if (thread.Peek() >= task.Peek())
  28.                 {
  29.                     task.Pop();
  30.                     thread.Dequeue();
  31.                 }
  32.                 else
  33.                 {
  34.                     thread.Dequeue();
  35.                 }
  36.             }
  37.  
  38.             Console.WriteLine($"Thread with value {thread.Peek()} killed task {task.Peek()}");
  39.  
  40.             Console.WriteLine(string.Join(" ", thread));
  41.         }
  42.  
  43.  
  44.     }
  45.  
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement