Created
February 2, 2018 05:20
-
-
Save unilecs/2ae528a42d7f6e12be3a67f3521ba4dc to your computer and use it in GitHub Desktop.
Задача 66: Степень двойки (@jinxonik)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{$APPTYPE CONSOLE} | |
//{$DEFINE ENTERLEN} | |
const | |
HugeNumber = 1E4000; | |
var | |
{$IFNDEF ENTERLEN} | |
SourceStr: String; | |
{$ENDIF} | |
Power, SourceLen, CurValLen, TotalLen: Integer; | |
CurValue, ControlVal: Extended; | |
begin | |
{$IFNDEF ENTERLEN} | |
Write('Enter source string: '); | |
ReadLn(SourceStr); | |
SourceLen := Length(SourceStr); | |
{$ELSE} | |
Write('Enter source string length: '); | |
ReadLn(SourceLen); | |
{$ENDIF} | |
if SourceLen <= 0 then WriteLn('String is empty!') | |
else | |
begin | |
Power := 1; | |
CurValLen := 1; | |
TotalLen := 1; | |
CurValue := 2; | |
ControlVal := 10; | |
while TotalLen < SourceLen do | |
begin | |
CurValue := CurValue * 2; | |
if CurValue >= ControlVal then | |
begin | |
Inc(CurValLen); | |
if ControlVal >= HugeNumber then | |
begin | |
CurValue := CurValue / HugeNumber; | |
ControlVal := ControlVal / HugeNumber; | |
end; | |
ControlVal := ControlVal * 10; | |
end; | |
Inc(Power); | |
Inc(TotalLen, CurValLen); | |
end; | |
WriteLn('Power of last number is ', Power, ' (last power value length is ', CurValLen, ' digits)'); | |
end; | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment