uses crt; var d:text; s,s1,h:string; i:longint; begin clrscr; assign(d,’input.pas’);reset(d); readln(d,s); readln(d,s1); for i:=1 to length(s) do h:=h+’ ‘; close(d); assign(d,’output.pas’);rewrite(d); repeat i:=pos(s,s1); writeln(d,i); delete(s1,i,length(s)); insert(h,s1,i); until pos(s,s1)=0; close(d); end.
Thuật toán thì như thế này
Tính độ dài của chuỗi St2 rồi chạy vòng lặp từ 0 đến độ dài chuỗi st2 – st1 rồi check điều kiện nếu
chuỗi từ ký tự đang index của st2 đến ký tự st2- st1 + index – 1 thì phải = = st1 thì là vị trí cần tìm :)) chưa chạy thử để tối chạy thử xem :)) .
uses crt;
var d:text; s,s1,h:string; i:longint;
begin
clrscr;
assign(d,’input.pas’);reset(d);
readln(d,s);
readln(d,s1);
for i:=1 to length(s) do h:=h+’ ‘;
close(d);
assign(d,’output.pas’);rewrite(d);
repeat
i:=pos(s,s1); writeln(d,i);
delete(s1,i,length(s));
insert(h,s1,i);
until pos(s,s1)=0;
close(d);
end.