#9717: 发一份代码造福全人类


Alan20210202 (上外附中马骋远)

學校 : 上海市娄山中学
編號 : 43837
來源 : [222.65.213.69]
最後登入時間 :
2016-01-10 17:19:31

//String Compressor
var
  st:ansistring;
  temp:char;
  counter,i:integer;
  first:boolean;
begin
while not eof do begin
  readln(st);
  counter:=1;
  first:=true;
  temp:=' ';
  while (length(st)>0) do begin
    if first then begin
      temp:=st[1];
      first:=false;
      delete(st,1,1);
    end else if((st[1] = temp)and(length(st)>0)) then begin
      counter := counter +  1;
      delete(st,1,1);
    end else if((st[1] <> temp)and(length(st)>0)) then begin
      if (counter > 2) then begin
        write(counter,temp);
      end else begin
        for i:=1 to counter do write(temp);
      end;
      counter:=1;
      temp:=st[1];
      delete(st,1,1);
    end;
  end;
  if (counter > 2) then begin
    writeln(counter,temp);
  end else begin
    for i:=1 to counter do write(temp);
  end;
  writeln();
end;
end.