Перейти из форума на сайт.

НовостиФайловые архивы
ПоискАктивные темыТоп лист
ПравилаКто в on-line?
Вход Забыли пароль? Первый раз на этом сайте? Регистрация
Компьютерный форум Ru.Board » Компьютеры » Прикладное программирование » Embarcadero RAD Studio

Модерирует : ShIvADeSt

 Версия для печати • ПодписатьсяДобавить в закладки
На первую страницук этому сообщениюк последнему сообщению

Открыть новую тему     Написать ответ в эту тему

AlekXL



Advanced Member
Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору


Код:
 
program Project47;
 
{$APPTYPE CONSOLE}
 
uses
  SysUtils;
 
type
TByteSet=set of Byte;
 
 
 
 
function NextElementFrom(const ByteSet: TByteSet; fromV:smallint=0; toVal:byte=255 ): smallint;
var
  bptr:AnsiChar absolute ByteSet;
  b: Byte;
  dwSize,dwordIt, dwStart:integer;
  curVal, mindwrd:Cardinal;
  label done;
begin
   dwSize:= ( SizeOf(ByteSet)+3) shr 2;
   result:=(fromV);
   dwStart:=result shr 5;
 
   result:= result and $FFE0;
   fromV:=fromV and 31;
   mindwrd:= $FFFFFFFF shl fromV;
   for dwordIt := dwStart to dwSize do begin
      curVal:=PCardinal( PAnsiChar(@bptr)+dwordIt*4)^;
      if (fromV>0) then  curval:=curVal and mindwrd;
 
      if curVal=0 then  begin Inc(result,4*8); fromV:=0; Continue end;
      if (Word(curVal)=0)then begin
            curVal:=curVal shr 16;
            Inc(result, 16);
       end;
 
      b:=Lo(curVal);
      if (b=0) then begin
        b:=Hi(curVal);
       Inc(result, 8);
      end;
 
      if (b and $F=0)then begin
        b:=b shr 4;
        Inc(result, 4);
      end;
 
      if Result>toVal then begin result:=-1; Exit; end;
 
      if (b and $3<>0) then begin//and
        if (b and $1=0)   then  inc(Result);
      end
      else begin
        if b and $C<>0 then begin
          if b and $4=0 then Inc(result,3)
          else Inc(Result,2);
        end
        else result:=-1
      end;
 
done:
     if result>toVal then result:=-1;
      Assert( (fromV<>0) or (result>=0) );
      exit;
    end;//for
   // No elements set
   result:=-1;
end;
 
var bs:TByteSet;
bt:smallint;
i,j:SmallInt;
begin
  try
    bs:=[2];
    bt:=NextElementFrom(bs,0);    
    for i := 0 to 255 do begin
      for j := 0 to 255 do
      begin
         bs:=[i];
         bt:=NextElementFrom(bs,j);
         Assert( ( (j>i) and (bt=-1) ) xor (bt=i) ) ;
      end;
 
    end;
    bs:=[];
    for i := 0 to 255 do Include(bs,i);
    for i := 0 to 255 do begin
          bt:=NextElementFrom(bs,i);
          Assert(i=bt);
 
    end;
       
 
    writeln(bt);
 
    { TODO -oUser -cConsole Main : Insert code here }
  except
    on E:Exception do
      Writeln(E.Classname, ': ', E.Message);
  end;
end.
 


Всего записей: 792 | Зарегистр. 24-04-2008 | Отправлено: 18:47 26-03-2015 | Исправлено: AlekXL, 12:44 27-03-2015
Открыть новую тему     Написать ответ в эту тему

На первую страницук этому сообщениюк последнему сообщению

Компьютерный форум Ru.Board » Компьютеры » Прикладное программирование » Embarcadero RAD Studio


Реклама на форуме Ru.Board.

Powered by Ikonboard "v2.1.7b" © 2000 Ikonboard.com
Modified by Ru.B0ard
© Ru.B0ard 2000-2024

BitCoin: 1NGG1chHtUvrtEqjeerQCKDMUi6S6CG4iC

Рейтинг.ru