这题没什么好说的,典型LCS问题,不过注意,poj里的数据,两个字串之间不一定只用空格隔开,读入的时候要注意

program poj1458;
var
  f:array[0..1000,0..1000] of integer;
  s1,s2,s:ansistring;
  i,j:integer;
function max(p,q:integer):integer;
begin
  if p>q then max:=p
    else max:=q;
end;
begin
  while not eof do
  begin
    readln(s);
    s:=s+' ';
    s1:='';
    s2:='';
    i:=1;
    while ((s[i]>='A') and (s[i]<='Z')) or ((s[i]>='a') and (s[i]<='z')) do
    begin
      s1:=s1+s[i];
      inc(i);
    end;
    while (s[i]<'A') or ((s[i]>'Z') and (s[i]<'a')) or (s[i]>'z') do inc(i);
    while ((s[i]>='A') and (s[i]<='Z')) or ((s[i]>='a') and (s[i]<='z')) do
    begin
      s2:=s2+s[i];
      inc(i);
    end;
    fillchar(f,sizeof(f),0);
    for i:=1 to length(s1) do
      for j:=1 to length(s2) do
        if s1[i]=s2[j] then f[i,j]:=f[i-1,j-1]+1
          else f[i,j]:=max(f[i-1,j],f[i,j-1]);
    writeln(f[length(s1),length(s2)]);
  end;
end.