How to delete duplicated letters in turbo pascal?

Can someone write code to delete duplicated letters in turbo pascal?

Input - pppppppaaaaaaasssssscccccaaaallll
Output - pascal

Comments

  • : Can someone write code to delete duplicated letters in turbo pascal?
    :
    : Input - pppppppaaaaaaasssssscccccaaaallll
    : Output - pascal
    :

    This works with consecutive duplicates only, like your example.[code][color=Blue]function delete_duplicate(s:string):string;
    var l:byte absolute s;
    ret:string;
    i:byte;ch:char;
    begin
    ret:='';ch:=#0;
    for i:=1 to l do
    if ch<>s[i] then begin
    ch:=s[i];
    ret:=ret+ch;
    end;
    delete_duplicate:=ret;
    end;

    begin
    writeln(delete_duplicate('ppppppppaaaaaassssccaaaaaalllllll'));
    readln;
    end.[/color][/code]
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion