| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
[Pascal]字符串类型记得使用ansistring !!!!!!!!!!!!!!!!因为string类型最长才255,不够的。
——————————————————————————
以下是ac代码:
{Program poj1458;
Const
maxn=400;
Var
i,j,k,n,m,p:longint;
A,B:array[0..maxn]of longint;
F:array[0..maxn,0..maxn]of longint;
S:ansistring;
{}Procedure ins(ch:char;p:longint);
begin
if p=1
then begin
inc(A[0]);
A[A[0]]:=ord(ch);
end
else begin
inc(B[0]);
B[B[0]]:=ord(ch);
end;
end;
{}Function max(a,b:longint):longint;
begin
if a<b then exit(b);
exit(a);
end;
Begin
while true do begin
readln(S);
if length(S)=0 then halt;
fillchar(A,sizeof(A),0);
fillchar(B,sizeof(B),0);
fillchar(F,sizeof(F),0);
p:=1;
for i:=1 to length(S) do
case S[i] of
'a'..'z':ins(S[i],p);
else p:=2;
end;
for i:=1 to A[0] do
for j:=1 to B[0] do begin
if A[i]=B[j]
then F[i,j]:=max(F[i-1,j],max(F[i-1,j-1]+1,F[i,j-1]))
else F[i,j]:=max(F[i-1,j],max(F[i-1,j-1], F[i,j-1]));
end;
writeln(F[A[0],B[0]]);
end;
End.}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator