Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:不是求最大公共子串?

Posted by vxk at 2003-11-13 18:56:23 on Problem 1580
In Reply To:不是求最大公共子串? Posted by:pladene at 2003-11-11 20:18:01
你觉得像吗?〉
program matchstring;
Var
A,B,C,d:String[255];
p,x,fd,vmax,vk:integer;
k,j:integer;
function gcd(m,n:integer):integer;
Var
fst:integer;
begin
 while n>0 do
  begin
   fst:=m;
   m:=n;
   n:=fst mod m;
  end;
  gcd:=abs(m);
end;
Begin
Readln(A);
While A<>'-1' do
begin
B:=copy(A,pos(' ',A)+1,length(A)-pos(' ',A));
A:=copy(A,1,pos(' ',A)-1);
p:=length(A)+length(B);
{writeln(A);
writeln(B); }
c:=a;
d:=b;
x:=0;
k:=1;
Repeat
 j:=1;
 vmax:=0;
 vk:=k;
 Repeat
  if a[vk]=b[j] then begin vk:=vk+1; j:=j+1;vmax:=vmax+1; end else
     begin
       j:=j+1;{vk:=vk+1;   }
     end;
 Until (j>length(B))OR(vk>length(A));
 k:=k+1;
 if vmax>x then x:=vmax;
Until k>length(A);
x:=2*x;
if x=p then writeln('appx(',c,',',d,') = 1')
 else
  if x=0 then writeln('appx(',c,',',d,') = 0')
  else
  begin
     fd:=gcd(x,p);
     x:=x div fd; p:=p div fd;
     writeln('appx(',c,',',d,') = ',x,'/',p);
  end;
readln(A);
end;
End.

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator