### Задача F. Сдвиги

Anonymous     Pascal/Delphi     28 Oct 2012
 ``` 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58``` ```var s, s1: string; k: integer; function BinToDec(const Value: string): string; var i, strLen, res: Integer; begin res := 0; strLen := Length(Value); for i := 1 to strLen do if Value[i] = '1' then res := res or (1 shl (strLen - i)) else res := res and not (1 shl (strLen - i)); Result := IntToStr(res); end; function DecToBin(const Number: string): string; var Num, Sign, aNum: Integer; Res: String; begin Res := ''; aNum := StrToInt(Number); if aNum >= 0 then Sign := 1 else Sign := -1; Num := Abs(aNum); repeat case Num mod 2 of 0: Res := '0' + Res; 1: Res := '1' + Res; end; Num := Num div 2; until Num = 0; if Sign = -1 then Res := '-' + Res; Result := Res; end; begin ReadLn(k); s := DecToBin(IntToStr(k)); s1 := s; for var i := 1 to length(s) - 1 do begin // Получаем сдвиг числа s1 := Copy(s1, 2, length(s1) - 1) + s1[1]; // Сравниваем числа if s < s1 then s := s1; end; WriteLn(BinToDec(s)); end. ```