desislava_topuzakova

06. Cake

Jul 6th, 2021
1,261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.40 KB | None | 0 0
  1. using System;
  2.  
  3. namespace ConsoleApp4
  4. {
  5.     class Program
  6.     {
  7.         static void Main(string[] args)
  8.         {
  9.             int width = int.Parse(Console.ReadLine());
  10.             int length = int.Parse(Console.ReadLine());
  11.             int countPieces = width * length;
  12.             //лице на тортата = брой на парчетата
  13.             //стоп: команда = "STOP"
  14.             //продължаваме: команда != "STOP"
  15.             //команда => "STOP" или брой парчета ("4")
  16.  
  17.             string command = Console.ReadLine();
  18.             while (command != "STOP")
  19.             {
  20.                 //брой взети парчета -> command = "2"
  21.                 int takenPieces = int.Parse(command);
  22.                 //извадим от общия брой взетите парчета
  23.                 countPieces -= takenPieces;
  24.                 //проверка дали имам останали парчета
  25.                 if (countPieces <= 0)
  26.                 {
  27.                     Console.WriteLine($"No more cake left! You need {Math.Abs(countPieces)} pieces more.");
  28.                     break;
  29.                 }
  30.                 command = Console.ReadLine();
  31.             }
  32.  
  33.             if (command == "STOP")
  34.             {
  35.                 Console.WriteLine($"{countPieces} pieces are left.");
  36.             }
  37.         }
  38.     }
  39. }
Advertisement
Add Comment
Please, Sign In to add comment