Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
38
Task/Run-length-encoding/PL-I/run-length-encoding.pli
Normal file
38
Task/Run-length-encoding/PL-I/run-length-encoding.pli
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
declare (c1, c2) character (1);
|
||||
declare run_length fixed binary;
|
||||
declare input file;
|
||||
|
||||
open file (input) title ('/RLE.DAT,type(text),recsize(20000)');
|
||||
on endfile (input) go to epilog;
|
||||
|
||||
get file (input) edit (c1) (a(1));
|
||||
run_length = 1;
|
||||
do forever;
|
||||
get file (input) edit (c2) (a(1));
|
||||
if c1 = c2 then
|
||||
run_length = run_length + 1;
|
||||
else
|
||||
do; put edit (trim(run_length), c1) (a); run_length=1; end;
|
||||
c1 = c2;
|
||||
end;
|
||||
epilog:
|
||||
put edit (trim(run_length), c1) (a);
|
||||
put skip;
|
||||
|
||||
|
||||
/* The reverse of the above operation: */
|
||||
declare c character (1);
|
||||
declare i fixed binary;
|
||||
declare new file;
|
||||
|
||||
open file (new) title ('/NEW.DAT,type(text),recsize(20000)');
|
||||
on endfile (new) stop;
|
||||
do forever;
|
||||
run_length = 0;
|
||||
do forever;
|
||||
get file (new) edit (c) (a(1));
|
||||
if index('0123456789', c) = 0 then leave;
|
||||
run_length = run_length*10 + c;
|
||||
end;
|
||||
put edit ((c do i = 1 to run_length)) (a);
|
||||
end;
|
||||
Loading…
Add table
Add a link
Reference in a new issue