Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- namespace C_sharp_Light
- {
- class Program
- {
- static void Main(string[] args)
- {
- Queue<int> buyers = new Queue<int>();
- bool isOpen = true;
- int money = 0;
- buyers = FillQueue();
- Console.WriteLine("Очередь заполнена");
- while (buyers.Count>0 && isOpen)
- {
- Console.WriteLine($"Нажмите Esc для выхода \n\n\n");
- Console.WriteLine($"Денег: {money}\nВ очереди - {buyers.Count}");
- Console.WriteLine($"У следующего покупателя сумма покупок = {buyers.Peek()}; \n\nНажмите - Enter - для обработки \nПробел - для пропуска покупателя до следующий итерации");
- ConsoleKeyInfo key = Console.ReadKey();
- switch (key.Key)
- {
- case ConsoleKey.Enter:
- Console.WriteLine("Покупатель обработан");
- money+=buyers.Dequeue();
- Console.ReadKey();
- break;
- case ConsoleKey.Spacebar:
- Console.WriteLine("Вы оставили покупателя на след. итерацию");
- Console.ReadKey();
- break;
- case ConsoleKey.Escape:
- isOpen = false;
- break;
- }
- Console.Clear();
- }
- if (isOpen!=false)
- {
- Console.Clear();
- Console.WriteLine($"Все покупатели обслужены. Вы заработали {money}");
- Console.ReadKey();
- }
- else
- {
- Console.Clear();
- Console.WriteLine($"Все прервали свой рабочий день, не обслужили всех покупателей. Вы заработали {money}");
- Console.ReadKey();
- }
- }
- static Queue<int> FillQueue()
- {
- Random rand = new Random();
- Queue<int> result = new Queue<int>();
- for (int i = 0; i < rand.Next(3,13); i++)
- {
- result.Enqueue(rand.Next(50, 1000));
- }
- return result;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement