Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace ConsoleApp1;
- using System.Text;
- public class Task04_02
- {
- public void Run()
- {
- Console.InputEncoding = Encoding.Unicode;
- Console.OutputEncoding = Encoding.Unicode;
- bool canExit = false;
- 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( "Введите размеры места под одну картину:" );
- Console.Write( "X : " );
- int imageSizeX = int.Parse( Console.ReadLine() );
- Console.Write( "Y : " );
- int imageSizeY = int.Parse( Console.ReadLine() );
- Console.WriteLine( "Введите количество картин, например 52:" );
- int imagesCount = int.Parse( Console.ReadLine() );
- int desiredColumnsCount = 3;
- int zoneColumnsCount = Math.Min( zoneSizeX / imageSizeX, desiredColumnsCount );
- int zoneRowsCount = zoneSizeY / imageSizeY;
- int zoneCapacity = zoneColumnsCount * zoneRowsCount;
- int remainedImages = Math.Max(0, imagesCount - zoneCapacity);
- int inRowsImagesCount = imagesCount - remainedImages;
- int imagesFullRowsCount = imagesCount / zoneColumnsCount;
- int remainedImagesInLastRow = imagesCount % zoneColumnsCount;
- bool isAdditionalRowRequired = remainedImagesInLastRow > 0;
- int totalRowsCount = imagesFullRowsCount + (isAdditionalRowRequired ? 1 : 0);
- bool hasEnoughSpaceForDesiredColumns = zoneColumnsCount == desiredColumnsCount;
- bool hasEnoughSpaceForAnyColumnsCount = remainedImages == 0;
- string resultText;
- if ( hasEnoughSpaceForDesiredColumns )
- {
- if( hasEnoughSpaceForAnyColumnsCount )
- resultText = $"Места хватит, все ок, влезут все {totalRowsCount} строк, содержащие {inRowsImagesCount} картинок";
- else
- resultText = $"Места недостаточно, влезут только {zoneRowsCount} строк, содержащие {inRowsImagesCount} картинок, " +
- $"останется {remainedImages} картинок";
- }
- else
- {
- if ( hasEnoughSpaceForAnyColumnsCount )
- resultText = $"Места недостаточно, чтобы разместить по {desiredColumnsCount} картинок в ряду. " +
- $"Но без учета этого требования влезут все {totalRowsCount} строк, содержащие {inRowsImagesCount} картинок";
- else
- resultText = $"Места недостаточно для размещения всех картинок, влезут только {zoneRowsCount} строк, " +
- $"содержащие {inRowsImagesCount} картинок, останется {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