Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace Scheduling
- {
- class Program
- {
- static void Main(string[] args)
- {
- Stack<int> tasks = new Stack<int>(Console.ReadLine()
- .Split(new[] { ", " }, StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse)
- .ToArray());
- Queue<int> threads = new Queue<int>(Console.ReadLine()
- .Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries)
- .Select(int.Parse)
- .ToArray());
- int taskToBeKilled = int.Parse(Console.ReadLine());
- while (threads.Count != 0 && tasks.Count != 0)
- {
- if (tasks.Peek() == taskToBeKilled)
- {
- Console.WriteLine($"Thread with value {threads.Peek()} killed task {taskToBeKilled}");
- foreach (var currentThread in threads)
- {
- Console.Write(currentThread + " ");
- }
- break;
- }
- if (threads.Peek() >= tasks.Peek())
- {
- threads.Dequeue();
- tasks.Pop();
- }
- else
- {
- threads.Dequeue();
- }
- }
- }
- }
- }
Add Comment
Please, Sign In to add comment