Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
41
Task/Run-length-encoding/XPL0/run-length-encoding.xpl0
Normal file
41
Task/Run-length-encoding/XPL0/run-length-encoding.xpl0
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
include c:\cxpl\codes; \intrinsic 'code' declarations
|
||||
string 0; \use zero-terminated strings, instead of MSb terminated
|
||||
|
||||
proc Compress(S); \Compress string using run-length encoding, & display it
|
||||
char S;
|
||||
int I, C0, C, N;
|
||||
[I:= 0;
|
||||
C0:= S(I); I:= I+1;
|
||||
repeat ChOut(0, C0);
|
||||
N:= 0;
|
||||
repeat C:= S(I); I:= I+1;
|
||||
N:= N+1;
|
||||
until C#C0;
|
||||
if N>1 then IntOut(0, N-1);
|
||||
C0:= C;
|
||||
until C=0;
|
||||
]; \Compress
|
||||
|
||||
proc Expand(S); \Expand compressed string, and display it
|
||||
char S;
|
||||
int I, C0, C, N;
|
||||
[I:= 0;
|
||||
C0:= S(I); I:= I+1;
|
||||
repeat ChOut(0, C0);
|
||||
C:= S(I); I:= I+1;
|
||||
if C>=^1 & C<=^9 then
|
||||
[N:= 0;
|
||||
while C>=^0 & C<=^9 do
|
||||
[N:= N*10 + C-^0;
|
||||
C:= S(I); I:= I+1;
|
||||
];
|
||||
while N do [ChOut(0, C0); N:= N-1];
|
||||
];
|
||||
C0:= C;
|
||||
until C=0;
|
||||
]; \Expand
|
||||
|
||||
[Compress("WWWWWWWWWWWWBWWWWWWWWWWWWBBBWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWW");
|
||||
CrLf(0);
|
||||
Expand("W11BW11B2W23BW13"); CrLf(0);
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue