Advertisement
IvetValcheva

Cake

Oct 9th, 2022
1,510
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.69 KB | None | 0 0
  1. using System;
  2.  
  3. namespace Cake
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             //1. Четем от конзолата ширина и дължина на тортата
  10.             int w = int.Parse(Console.ReadLine());
  11.             int h = int.Parse(Console.ReadLine());
  12.  
  13.             //2. Изчисляваме колко са парчетата торта
  14.             int cakeSize = w * h;
  15.  
  16.             string input = Console.ReadLine();
  17.             int cakePeieces;
  18.  
  19.             //3. Създаваме цикъл, който да се изпълнява до получаване на "STOP"
  20.             while (input!="STOP")
  21.             {
  22.                 cakePeieces = int.Parse(input);
  23.                 // => проверяваме дали има достатъчно
  24.                 if (cakePeieces > cakeSize)
  25.                 {
  26.                     // => ако няма достатъчно:
  27.                     // ==> отпечатваме колко недостигат и спираме цикъла
  28.                     Console.WriteLine($"No more cake left! You need {Math.Abs(cakePeieces-cakeSize)} pieces more.");
  29.                     cakeSize -= cakePeieces;
  30.                     break;
  31.                 }
  32.  
  33.                 // => ако има достатъчно:
  34.                 // ==> изваждаме броя, който си взимат от отаналите парчета
  35.                 cakeSize -= cakePeieces;
  36.  
  37.                 input = Console.ReadLine();
  38.             }
  39.  
  40.             if (cakeSize>0)
  41.             {
  42.                 Console.WriteLine($"{cakeSize} pieces are left.");
  43.             }
  44.  
  45.         }
  46.     }
  47. }
  48.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement