Pascal

Modified: Wednesday, 22-12-2021 07:00 AM

Đổi 'anh' thành 'em' và ngược lại


var i,j:byte;
    st:string;
begin
    st:='anh em nha Pascal that la Pro, em la mot con ga trong so nhung anh em nay.';
    for i:=1 to length(st) do 
    if (st[i]+st[i+1]+st[i+2]='anh') then 
       begin
         insert('em',st,i);
         delete(st,i+2,3);
       end
       else if (st[i]+st[i+1]='em') then
       begin
         insert('anh',st,i);
         delete(st,i+3,2);
       end;
    writeln(st);
    readln;
end.