Advertisement
Guest User

Untitled

a guest
Oct 24th, 2019
218
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.23 KB | None | 0 0
  1. using System;
  2. using System.Collections;
  3. using System.Linq;
  4.  
  5. namespace _02_Make_a_Salad
  6. {
  7.     class Program
  8.     {
  9.         static void Main(string[] args)
  10.         {
  11.             Queue vegies = new Queue(Console.ReadLine().Split());
  12.             Stack calories = new Stack(Console.ReadLine().Split().Select(int.Parse).ToList());
  13.  
  14.             Queue madeSalads = new Queue();
  15.  
  16.             while (true)
  17.             {
  18.                 if (calories.Count <= 0) break;
  19.                 if (vegies.Count <= 0) break;
  20.  
  21.                 int saladCal = (int)calories.Peek();
  22.  
  23.                 while (true)
  24.                 {
  25.                     string vegetable = (string)vegies.Dequeue();
  26.                    
  27.                     switch (vegetable)
  28.                     {
  29.                         case "tomato":
  30.                             saladCal -= 80;
  31.                             break;
  32.                         case "carrot":
  33.                             saladCal -= 136;
  34.                             break;
  35.                         case "lettuce":
  36.                             saladCal -= 109;
  37.                             break;
  38.                         case "potato":
  39.                             saladCal -= 215;
  40.                             break;
  41.                     }
  42.                     if (saladCal <= 0)
  43.                     {
  44.                         int num = (int)calories.Pop();
  45.                         madeSalads.Enqueue(num);
  46.                         break;
  47.                     }
  48.                     if (vegies.Count <= 0) break;
  49.                 }
  50.             }
  51.  
  52.             foreach (var salad in madeSalads)
  53.             {
  54.                 Console.Write(salad + " ");
  55.             }
  56.             Console.WriteLine();
  57.            
  58.  
  59.             if (vegies.Count > 0)
  60.             {
  61.                 foreach (var veg in vegies)
  62.                 {
  63.                     Console.Write(veg + " ");
  64.                 }
  65.                 Console.WriteLine();
  66.             }
  67.            
  68.  
  69.             if (calories.Count > 0)
  70.             {
  71.                 foreach (var cal in calories)
  72.                 {
  73.                     Console.Write(cal + " ");
  74.                 }
  75.                 Console.WriteLine();
  76.             }
  77.         }
  78.     }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement