Написала программу. Нужно из числа удалить самую длинную одинаковую последовательность.....Работает, все....Вот только когда ввожу 1000 нули не удаляет.....Где ошибка?
Код:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 | uses crt;
var chislo,chislo2,
st: longint ;
c,old_c,
i,
how,h,maxLenght,
p,position: integer ;
function get_int(chislo: longint ;pos: integer ): integer ;
var
c,i: integer ;
o: longint ;
begin
o := chislo;
i := 0 ;
c := - 1 ;
while o> 0 do begin
inc(i);
if i = pos then begin
c := o mod 10 ;
o := 0 ;
end ;
o := o div 10 ;
end ;
get_int := c;
end ;
begin
clrscr;
write ( 'Write: ' );
readln(chislo);
c := 0 ;
i := 0 ;
old_c := 0 ;
h:= 0 ;
maxLenght := 0 ;
while c>= 0 do begin
inc(i);
c := get_int(chislo,i);
if c = old_c then begin
inc(h);
if h>maxLenght then begin
maxLenght := h;
end ;
end else begin
if h=maxLenght then
position := p;
p := i;
h := 1 ;
end ;
old_c := c;
end ;
if h=maxLenght then
position := p;
i := 0 ;
c := 0 ;
st := 1 ;
while c>= 0 do begin
inc(i);
c := get_int(chislo,i);
if i = position then begin
i := i+maxLenght;
c := get_int(chislo,i);
end ;
if c>= 0 then begin
chislo2 := chislo2 + st * c;
st:=st* 10 ;
end ;
end ;
writeln (chislo2);
readkey;
end .
|
Admin: Пользуемся тегами!