Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function Compare2(s1, s2: string): Integer;
- var
- i, mL, s1L, s2L: Integer;
- begin
- if s1 = s2 then
- Exit;
- s1L := Length(s1);
- s2L := Length(s2);
- if (s1L <= 0) or (s2L <= 0) then
- if (s1L < s2L) then
- Result := -1
- else
- Result := 1;
- if (Result <> 0) then
- Exit;
- Result := -1;
- mL := Min(s1L, s2L);
- for i := 1 to mL do
- if (s1[i] <> s2[i]) then
- begin
- if (s1[i] > s2[i]) then
- Result := 1;
- Exit;
- end;
- if (s1L > s2L) then
- Result := 1;
- end;
- function GetRelation(s1, s2: string): string;
- var
- r: Integer;
- begin
- r := Compare2(s1, s2);
- case r of
- -1: Result := ('"' + s1 + '" < "' + s2 + '"');
- 0: Result := ('"' + s1 + '" = "' + s2 + '"');
- 1: Result := ('"' + s1 + '" > "' + s2 + '"');
- end;
- end;
- begin
- ClearDebug;
- WriteLn(GetRelation('ABCD A', 'ABCD B'));
- WriteLn(GetRelation('ABCD B', 'ABCD B'));
- WriteLn(GetRelation('ABCD C', 'ABCD B'));
- end.
Advertisement
Add Comment
Please, Sign In to add comment