Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@unilecs
Created February 2, 2018 05:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unilecs/2ae528a42d7f6e12be3a67f3521ba4dc to your computer and use it in GitHub Desktop.
Save unilecs/2ae528a42d7f6e12be3a67f3521ba4dc to your computer and use it in GitHub Desktop.
Задача 66: Степень двойки (@jinxonik)
{$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