Advertisement
silvana1303

lootbox

Oct 21st, 2020
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.46 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. namespace zadacha
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             int[] queue = Console.ReadLine().Split().Select(int.Parse).ToArray();
  12.             int[] stack = Console.ReadLine().Split().Select(int.Parse).ToArray();
  13.  
  14.             Queue<int> first = new Queue<int>(queue);
  15.             Stack<int> second = new Stack<int>(stack);
  16.  
  17.             List<int> claimed = new List<int>();
  18.  
  19.             while (true)
  20.             {
  21.                 if ((first.Peek() + second.Peek()) % 2 == 0)
  22.                 {
  23.                     claimed.Add(first.Dequeue() + second.Pop());
  24.                 }
  25.                 else
  26.                 {
  27.                     first.Enqueue(second.Pop());
  28.                 }
  29.  
  30.                 if (first.Count == 0)
  31.                 {
  32.                     Console.WriteLine("First lootbox is empty");
  33.                     break;
  34.                 }
  35.  
  36.                 if (second.Count == 0)
  37.                 {
  38.                     Console.WriteLine("Second lootbox is empty");
  39.                     break;
  40.                 }
  41.             }
  42.  
  43.             if (claimed.Sum() >= 100)
  44.             {
  45.                 Console.WriteLine($"Your loot was epic! Value: {claimed.Sum()}");
  46.             }
  47.             else
  48.             {
  49.                 Console.WriteLine($"Your loot was poor... Value: {claimed.Sum()}");
  50.             }
  51.         }
  52.     }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement