Advertisement
_CodeBehind

SN

Jun 22nd, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.94 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4.  
  5. public class ShopDatabase
  6. {
  7.     public static void Main()
  8.     {
  9.         var flowers = new Queue<long>(Console.ReadLine()
  10.             .Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries)
  11.             .Select(long.Parse));
  12.         var buckets = new Stack<long>(Console.ReadLine()
  13.             .Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries)
  14.             .Select(long.Parse));
  15.  
  16.         var secondNatures = new List<long>(0);
  17.  
  18.         while (true)
  19.         {
  20.             if (flowers.Count == 0)
  21.             {
  22.                 Console.WriteLine(string.Join(" ", buckets));
  23.                 break;
  24.             }
  25.             if (buckets.Count == 0)
  26.             {
  27.                 Console.WriteLine(string.Join(" ", flowers));
  28.                 break;
  29.             }
  30.  
  31.             var currentFlower = flowers.Dequeue();
  32.             var currentBucket = buckets.Pop();
  33.  
  34.             if (currentBucket > currentFlower)
  35.             {
  36.                 var waterToAdd = currentBucket - currentFlower;
  37.                 if (buckets.Count != 0)
  38.                 {
  39.                     buckets.Push(buckets.Pop() + waterToAdd);
  40.                 }
  41.                 else
  42.                 {
  43.                     buckets.Push(waterToAdd);
  44.                 }
  45.             }
  46.             else if (currentFlower > currentBucket)
  47.             {
  48.                 var difference = currentFlower - currentBucket;
  49.                 var temp = flowers.ToList();
  50.                 temp.Insert(0,difference);
  51.                 flowers = new Queue<long>(temp);
  52.             }
  53.             else
  54.             {
  55.                 secondNatures.Add(currentFlower);
  56.             }
  57.         }
  58.         if (secondNatures.Count != 0)
  59.         {
  60.             Console.WriteLine(string.Join(" ", secondNatures));
  61.         }
  62.         else
  63.         {
  64.             Console.WriteLine("None");
  65.         }
  66.     }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement