Advertisement
silvana1303

flower wreath

Oct 21st, 2020
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.68 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[] stack = Console.ReadLine().Split(", ").Select(int.Parse).ToArray();
  12.             int[] queue = Console.ReadLine().Split(", ").Select(int.Parse).ToArray();
  13.  
  14.             Stack<int> lilies = new Stack<int>(stack);
  15.             Queue<int> roses = new Queue<int>(queue);
  16.  
  17.             List<int> storage = new List<int>();
  18.  
  19.             int count = 0;
  20.             int wreath = 0;
  21.  
  22.             while (lilies.Any() && roses.Any())
  23.             {
  24.                 if (lilies.Peek() + roses.Peek() == 15)
  25.                 {
  26.                     count++;
  27.                     lilies.Pop();
  28.                     roses.Dequeue();
  29.                 }
  30.                 else if (lilies.Peek() + roses.Peek() > 15)
  31.                 {
  32.                     lilies.Push(lilies.Pop() - 2);
  33.                 }
  34.                 else
  35.                 {
  36.                     storage.Add(lilies.Pop());
  37.                     storage.Add(roses.Dequeue());
  38.                 }
  39.             }
  40.  
  41.             if (storage.Count > 0)
  42.             {
  43.                 if (storage.Sum() > 15)
  44.                 {
  45.                     wreath = storage.Sum() / 15;
  46.                     count += wreath;
  47.                 }
  48.             }
  49.  
  50.             if (count >= 5)
  51.             {
  52.                 Console.WriteLine($"You made it, you are going to the competition with {count} wreaths!");
  53.             }
  54.             else
  55.             {
  56.                 Console.WriteLine($"You didn't make it, you need {5-count} wreaths more!");
  57.             }
  58.         }
  59.     }
  60. }
  61.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement