Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,45 @@
|
|||
MODULE StrCollapse;
|
||||
FROM InOut IMPORT WriteString, WriteCard, WriteLn;
|
||||
FROM Strings IMPORT Length;
|
||||
|
||||
(* Collapse a string *)
|
||||
PROCEDURE Collapse(in: ARRAY OF CHAR; VAR out: ARRAY OF CHAR);
|
||||
VAR i, o: CARDINAL;
|
||||
BEGIN
|
||||
i := 0;
|
||||
o := 0;
|
||||
WHILE (i < HIGH(in)) AND (in[i] # CHR(0)) DO
|
||||
IF (o = 0) OR (out[o-1] # in[i]) THEN
|
||||
out[o] := in[i];
|
||||
INC(o);
|
||||
END;
|
||||
INC(i);
|
||||
END;
|
||||
out[o] := CHR(0);
|
||||
END Collapse;
|
||||
|
||||
(* Display a string and collapse it as stated in the task *)
|
||||
PROCEDURE Task(s: ARRAY OF CHAR);
|
||||
VAR buf: ARRAY [0..127] OF CHAR;
|
||||
PROCEDURE LengthAndBrackets(s: ARRAY OF CHAR);
|
||||
BEGIN
|
||||
WriteCard(Length(s), 2);
|
||||
WriteString(" <<<");
|
||||
WriteString(s);
|
||||
WriteString(">>>");
|
||||
WriteLn();
|
||||
END LengthAndBrackets;
|
||||
BEGIN
|
||||
LengthAndBrackets(s);
|
||||
Collapse(s, buf);
|
||||
LengthAndBrackets(buf);
|
||||
WriteLn();
|
||||
END Task;
|
||||
|
||||
BEGIN
|
||||
Task("");
|
||||
Task('"If I were two-faced, would I be wearing this one?" --- Abraham Lincoln ');
|
||||
Task("..1111111111111111111111111111111111111111111111111111111111111117777888");
|
||||
Task("I never give 'em hell, I just tell the truth, and they think it's hell. ");
|
||||
Task(" --- Harry S Truman ");
|
||||
END StrCollapse.
|
||||
Loading…
Add table
Add a link
Reference in a new issue