pascal程序:
{简易压缩算法}
const
s:string='111000';
var
a:array[11000] of char;
b:array[11000] of integer;
i,j,k,n:integer;
begin
n:=1;
k:=length(s);
a[n]:=s[n];
b[n]:=1;
for i:=2 to k do begin
if s[i]=a[n] then inc(b[n]) else begin
inc(n);
a[n]:=s[i];
b[n]:=1;
end;
end;
for i:=1 to n do
if i=1 then write(a[i],'',b[i]:0)
else write('',b[i]:0);
end
forpro程序:
{简易压缩算法}
CLEAR
SET TALK OFF
DIMENSION a(1000) as Character
DIMENSION b(1000) as Integer
s='111000'
n=1
k=len(s)
a[n]=SUBSTR(s,n,1)
b[n]=1
for i=2 to k
if SUBSTR(s,i,1)=a[n] then
b[n]=b[n]+1
else
n=n+1
a[n]=SUBSTR(s,i,1)
b[n]=1
endif
NEXT i
s=''
for j=1 to n
if j=1 then
s=s+a[j]+''+allTRIM(STR(b[j] ))
else
s=s+''+allTRIM(STR(b[j]))
endif
NEXT j
s
RETURN
欢迎分享,转载请注明来源:品搜搜测评网