Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace ConsoleApp1;
- using System.Text;
- public class Task04_03
- {
- public void Run()
- {
- Console.InputEncoding = Encoding.Unicode;
- Console.OutputEncoding = Encoding.Unicode;
- bool canExit = false;
- int imagesPerOneRow = 3;
- while ( canExit == false )
- {
- Console.WriteLine( "Введите размеры зоны" );
- Console.Write( "X : " );
- int zoneSizeX = int.Parse( Console.ReadLine() );
- Console.Write( "Y : " );
- int zoneSizeY = int.Parse( Console.ReadLine() );
- Console.WriteLine( $"Размеры зоны: {zoneSizeX} x {zoneSizeY}" );
- Console.WriteLine( "Введите количество картин, например 52:" );
- int imagesCount = int.Parse( Console.ReadLine() );
- int zoneCapacity = zoneSizeX * zoneSizeY;
- int imagesFullRowsCount = imagesCount / imagesPerOneRow;
- int imagesInLastRow = imagesCount % imagesPerOneRow;
- bool isRequiredAdditionalRow = imagesInLastRow > 0;
- int imagesRowsTotalCount = imagesFullRowsCount + (isRequiredAdditionalRow ? 1 : 0);
- bool hasEnoughSpace = imagesCount <= zoneCapacity;
- int remainedImages = Math.Max( 0, imagesCount - zoneCapacity );
- string resultText;
- if ( hasEnoughSpace )
- {
- resultText = $"Места хватит, все ок, влезут все {imagesRowsTotalCount} строк, содержащие {imagesCount} картинок";
- }
- else
- {
- resultText = $"Места недостаточно для размещения всех картинок, влезут только {zoneSizeY} строк, " +
- $"содержащие {zoneCapacity} картинок, останется {remainedImages} картинок";
- }
- Console.WriteLine( $"{resultText} \n" );
- Console.WriteLine("Continue? Enter 'n' for exit");
- string continueAnswer = Console.ReadLine();
- string exitAnswer = "n";
- canExit = string.Equals( continueAnswer, exitAnswer );
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement