Longest common substring: Difference between revisions
→{{header|Pascal}}
Thundergnat (talk | contribs) m (syntax highlighting fixup automation) |
|||
Line 1,560:
<pre>test</pre>
(*)=={{header|Pascal}}==
=== using FreePascal ===
{{trans|Delphi}}
{{works with|Free Pascal| 3.2.2 }}
<syntaxhighlight lang="pascal">(*)
PROGRAM LongestCommonSubString.pas;
{$WARN 6058 off : Call to subroutine "$1" marked as inline is not inlined} // Use for variants
{$IFDEF FPC}
{$ELSE}
{$ENDIF}
(*)
The free and readable alternative at C/C++ speeds
compiles natively to almost any platform, including raspberry PI *
Line 1,582 ⟶ 1,584:
https://www.freepascal.org/advantage.var
Version without `USES SysUtils, Variants ;` and without `SubStr`, we do not need it here...
(*)
FUNCTION IFF ( Cond: boolean; A, B: string ) : string ;
BEGIN IF ( Cond ) THEN IFF := A ELSE IFF := B ; END ;
FUNCTION
VAR
j : Integer = 0 ;
k : Integer = 0 ;
S : string = '' ;
BEGIN
lcss := '' ;
FOR j := 0 TO length ( S1 ) DO
BEGIN
FOR k := length ( S1 ) - j DOWNTO 1 DO
BEGIN
S := S1 [ ( j + 1 )
IF ( pos ( S, S2 ) > 0 ) AND
( length ( S ) > length ( lcss ) ) THEN
BEGIN
lcss := S ;
BREAK ;
END ;
END;
END;
VAR
S1: string = 'thisisatest' ;
S2: string = 'testing123isatesting' ;
BEGIN
IF ParamCount = 2 THEN
BEGIN
S1 := IFF( ( ParamStr ( 1 ) > '' ), ParamStr ( 1 ) , S1 );
S2 := IFF( ( ParamStr ( 2 ) > '' ), ParamStr ( 2 ) , S1 );
END;
Writeln ( 'string A = ', S1 ) ;
Writeln ( 'string B = ', S2 ) ;
WriteLn ( Lcss ( S1, S2 ) ) ;
END.
(*)
</syntaxhighlight>
<PRE>JPD 2021/06/18
Output:
Line 1,742 ⟶ 1,674:
test
</PRE>(*)
=={{header|Perl}}==
|