| ||||||||||
| 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 | |||||||||
尽量减少每次比较的消耗In Reply To:这样都要超时?大牛帮忙! Posted by:JiangLY at 2005-05-01 00:02:36 > label 1;
> var
> d:array[1..10000] of string;
> s,p:string;
> i,l:longint;
> function checkdelete(a,b:string):boolean;
> var
> i:integer;
> t:string;
> begin
> checkdelete:=false;
> for i:=1 to length(a) do
> begin
> t:=a;
> delete(t,i,1);
> if t=b then
> begin
> checkdelete:=true;
> exit;
> end;
> end;
> end;
> function checkinsert(a,b:string):boolean;
> var
> i:integer;
> t:string;
> begin
> checkinsert:=false;
> for i:=1 to length(b) do
> begin
> t:=b;
> delete(t,i,1);
> if t=a then
> begin
> checkinsert:=true;
> exit;
> end;
> end;
> end;
> function checkreplace(a,b:string):boolean;
> var
> i,k:integer;
> begin
> k:=0;
> for i:=1 to length(a) do
> if a[i]<>b[i] then inc(k);
> if k=1 then checkreplace:=true
> else checkreplace:=false;
> end;
> begin
> readln(p);
> l:=0;
> while p<>'#' do
> begin
> inc(l);
> d[l]:=p;
> readln(p);
> end;
> readln(s);
> while s<>'#' do
> begin
> for i:=1 to l do
> if d[i]=s then
> begin
> writeln(s,' is correct');
> goto 1;
> end;
> write(s,':');
> for i:=1 to l do
> if length(d[i])=length(s) then
> begin
> if checkreplace(s,d[i]) then write(' ',d[i]);
> end
> else
> if length(d[i])=length(s)+1 then
> begin
> if checkinsert(s,d[i]) then write(' ',d[i]);
> end
> else
> if length(d[i])+1=length(s) then
> begin
> if checkdelete(s,d[i]) then write(' ',d[i]);
> end;
> writeln;
> 1:
> readln(s);
> end;
> end.
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator