Advertisement
sergezhu

Untitled

Apr 1st, 2023
740
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.93 KB | None | 0 0
  1. namespace ConsoleApp1;
  2.  
  3. using System.Text;
  4.  
  5. public class Task04_03
  6. {
  7.     public void Run()
  8.     {
  9.         Console.InputEncoding = Encoding.Unicode;
  10.         Console.OutputEncoding = Encoding.Unicode;
  11.  
  12.         bool canExit = false;
  13.         int imagesPerOneRow = 3;
  14.  
  15.         while ( canExit == false )
  16.         {
  17.             Console.WriteLine( "Введите размеры зоны" );
  18.             Console.Write( "X : " );
  19.             int zoneSizeX = int.Parse( Console.ReadLine() );
  20.  
  21.             Console.Write( "Y : " );
  22.             int zoneSizeY = int.Parse( Console.ReadLine() );
  23.             Console.WriteLine( $"Размеры зоны: {zoneSizeX} x {zoneSizeY}" );
  24.  
  25.             Console.WriteLine( "Введите количество картин, например 52:" );
  26.             int imagesCount = int.Parse( Console.ReadLine() );
  27.             int zoneCapacity = zoneSizeX * zoneSizeY;
  28.  
  29.             int imagesFullRowsCount = imagesCount / imagesPerOneRow;
  30.             int imagesInLastRow = imagesCount % imagesPerOneRow;
  31.             bool isRequiredAdditionalRow = imagesInLastRow > 0;
  32.             int imagesRowsTotalCount = imagesFullRowsCount + (isRequiredAdditionalRow ? 1 : 0);
  33.  
  34.             bool hasEnoughSpace = imagesCount <= zoneCapacity;
  35.             int remainedImages = Math.Max( 0, imagesCount - zoneCapacity );
  36.  
  37.             string resultText;
  38.  
  39.             if ( hasEnoughSpace )
  40.             {
  41.                 resultText = $"Места хватит, все ок, влезут все {imagesRowsTotalCount} строк, содержащие {imagesCount} картинок";
  42.                
  43.             }
  44.             else
  45.             {
  46.                 resultText = $"Места недостаточно для размещения всех картинок, влезут только {zoneSizeY} строк, " +
  47.                              $"содержащие {zoneCapacity} картинок, останется {remainedImages} картинок";
  48.             }
  49.  
  50.             Console.WriteLine( $"{resultText} \n" );
  51.             Console.WriteLine("Continue? Enter 'n' for exit");
  52.             string continueAnswer = Console.ReadLine();
  53.             string exitAnswer = "n";
  54.  
  55.             canExit = string.Equals( continueAnswer, exitAnswer );
  56.         }
  57.     }
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement