U E D R , A S I H C RSS

Slurpys/강인수

~cpp 
function  HasDorEAtFirst (const S: String): Boolean;
function  HasGAtLast (const S: String; APos: Integer): Boolean;
function  FindF (const S: String): Integer;
function  IsSlump (const S: String): Boolean;

function  IsSlimp (const S: String): Boolean;
function  IsSlurpy (const S: String): Boolean;

implementation

function  HasDorEAtFirst (const S: String): Boolean;
begin
  Result := (S[1] = 'D') or (S[1] = 'E');
end;

function  HasGAtLast (const S: String; APos: Integer): Boolean;
begin
  Result := (S[APos+1] = 'G') and (APos+1 = Length(S));
end;

function  FindF (const S: String): Integer;
var
  i:          Integer;
  FirstFind:  Boolean;
begin
  FirstFind := False;
  Result := -1;

  if S[2] <> 'F' then
  begin
    exit;
  end;

  for i:=2 to Length(S) do
  begin
    if S[i] = 'F' then
    begin
      FirstFind := True;
    end else
    begin
      if FirstFind then
      begin
        Result := i-1;
        exit;
      end;
    end;
  end;
end;

function  IsSlump (const S: String): Boolean;
var
  FPos: Integer;
begin
  Result := False;

  try
    if Length(S) < 3 then
    begin
      exit;
    end;

    if HasDorEAtFirst (S) = False then
    begin
      exit;
    end;

    FPos := FindF (S);
    if FPos = -1 then
    begin
      exit;
    end;

    if HasGAtLast (S,FPos) then
    begin
      Result := True;
      exit;
    end;

    if IsSlump(Copy(S, FPos+1, MAX_STR_LEN)) then
    begin
      Result := True;
      exit;
    end;
  except
    Result := False;
  end;
end;

function  IsSlimp (const S: String): Boolean;
begin
  Result := False;

  try
    if Length(S) < 2 then
    begin
      exit;
    end;

    if S[1] <> 'A' then
    begin
      exit;
    end;

    if Length(S) = 2 then
    begin
      Result := (S[2] = 'H');
      exit;
    end;

    if S[Length(S)] <> 'C' then
    begin
      exit;
    end;

    if S[2] = 'B' then
    begin
      Result := IsSlimp(Copy(S,3,Length(S)-3));
      exit;
    end else
    begin
      Result := IsSlump(Copy(S,2,Length(S)-2));
      exit;
    end;
  except
    Result := False;
  end;
end;

function  IsSlurpy (const S: String): Boolean;
var
  i: Integer;
begin
  Result := False;

  for i:=1 to Length(S)-1 do
  begin
    if IsSlimp(Copy(S,1,i)) and IsSlump(Copy(S,i+1,MAX_STR_LEN)) then
    begin
      Result := True;
      exit;
    end;
  end;
end;


오랜만에 코딩해본다. ㅠ.ㅠ
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:28:02
Processing time 0.0273 sec