program PatS;

{ Plain pattern search. }

var
   Txt, Pat : String;
   FoundPos : LongInt;
   Index    : LongInt;

function Search(p, t : String) : LongInt;
var
   Index, SubIndex :  LongInt;
begin
   Index := 0;
   SubIndex := 0;
   while (Index <= Length(t) - Length(p)) and (SubIndex < Length(p)) do
   begin
      SubIndex := 0;
      Inc(Index);
      while (SubIndex < Length(p))
	 and (t[Index + SubIndex] = p[SubIndex + 1]) do
	 Inc(SubIndex);
   end;
   if SubIndex = Length(p) then Search := Index else Search := 0;
end;

begin
   Write('Text: ');
   Readln(Txt);
   Write('Pattern: ');
   Readln(Pat);
   FoundPos := Search(Pat,Txt);
   if FoundPos = 0 then
      Writeln('Not found.')
   else
   begin
      Writeln(Txt);
      for Index := 1 to FoundPos - 1 do Write(' ');
      Writeln('^');
   end;
end.

