What can be wrong with my program. When I use Turbo Pascal I get rigth answer, but if I use Delphi i get wrong(+) This test:   01102103   My code:   Program t1165;   Const MaxD=400;   Type  ResType=array[1..MaxD]of integer;   Var A       :string[250];     Min,Cur :string[250];     i,mfrom :integer;     GetOk   :boolean;     wor     :array[1..251]of integer;   Procedure MakeWor(S:string); Var i,j,p :integer;  begin   FillChar(wor,SizeOf(wor),0);   for i:=length(S) downto 1 do begin    val(S[i],j,p);    wor[length(S)-i+1]:=j;   end;  end;   Function ConvertInStr(len:integer):string; var i     :integer;     l,ans :string[250];  begin   ans:='';   for i:=1 to len do begin    str(wor[i],l);    ans:=l+ans;   end;   ConvertInStr:=ans;  end;   Function GetPred(S:string):string; var i,j,flag :integer;  begin   flag:=0;   MakeWor(S);   wor[1]:=wor[1]-1;   if wor[1]=-1 then begin    for j:=2 to 251 do     if wor[j]>0 then break;    wor[j]:=wor[j]-1;    if wor[j]=0 then flag:=-1;    for i:=1 to j-1 do wor[i]:=9;   end;   GetPred:=ConvertInStr(length(S)+flag);  end;   Function GetNext(S:string):string; var i,j,flag :integer;  begin   flag:=0;   MakeWor(S);   wor[1]:=wor[1]+1;   for i:=1 to 251 do    if wor[i]>9 then begin     wor[i+1]:=wor[i+1]+(wor[i] div 10);     wor[i]:=wor[i] mod 10;    end;   if wor[length(S)+1]>0 then flag:=1;   GetNext:=ConvertInStr(length(S)+flag);  end;   Function GetNextXX(StrX:string):string; Var i,j,p :integer;     ans,l :string[250];     mas   :array[1..251]of byte;  begin   FillChar(mas,SizeOf(mas),0);   for i:=length(StrX) downto 1 do begin    val(StrX[i],j,p);    mas[length(StrX)-i+1]:=j;   end;   ans:='';   mas[1]:=mas[1]+1;   for i:=1 to 251 do    if mas[i]>9 then begin     mas[i+1]:=mas[i+1]+(mas[i] div 10);     mas[i]:=mas[i] mod 10;    end;   for i:=1 to length(StrX) do begin    str(mas[i],l);    ans:=l+ans;   end;   GetNextXX:=ans;  end;   Function GetMin(from:integer):string; Var BeginStr   :string[250];     MaskStr    :string[250];     second     :string[250];     Next       :string[250];     CurPos     :integer;     MaskBegin  :integer;     i,j,t      :integer;     len        :integer;     ok,yes     :boolean;  begin   BeginStr:=copy(A,1,from);   MaskStr:=GetNextXX(BeginStr);   MaskBegin:=from+1;   if A[MaskBegin]='0' then begin    GetOk:=false;    exit;   end;   if MaskStr<BeginStr then    MaskBegin:=MaskBegin+1;   len:=length(MaskStr);   for i:=MaskBegin-1 to length(A) do begin    ok:=true;    for j:=1 to len do begin     if i+j>length(A) then break;     if A[i+j]<>MaskStr[j] then ok:=false;    end;    if ok then begin     yes:=true;     second:=copy(A,from+1,i+j-from);     if i+j>length(A) then      for t:=j to len do second:=second+MaskStr[t];     CurPos:=i+j+1;     if Pos(BeginStr,GetPred(second))=0 then yes:=false;     Next:=second;     While True do begin      Next:=GetNext(Next);      for t:=CurPos to CurPos+length(Next)-1 do begin       if t>length(A) then break;       if A[t]<>Next[t-CurPos+1] then yes:=false;      end;      CurPos:=CurPos+length(Next);      if CurPos>length(A) then break;     end;     if yes then begin      GetOk:=true;      GetMin:=GetPred(second);      exit;     end;    end;   end;   GetOk:=false;  end;   Procedure MakeResult; Var i,j,k   :integer;     um,l    :integer;     A,B,C,S :ResType;  begin   FillChar(A,SizeOf(A),0);   for i:=1 to length(Min) do begin    val(Min[i],k,j);    A[length(Min)+1-i]:=k;   end;   FillChar(S,SizeOf(S),0);   for i:=1 to length(Min)-1 do begin    FillChar(B,SizeOf(B),0);    B[i]:=9;    FillChar(C,SizeOf(C),0);    um:=0;    for j:=1 to MaxD do begin      l:=b[j]*i+um;      c[j]:=l mod 10;      um:=l div 10;     end;    um:=0;    for j:=1 to MaxD do begin      l:=c[j]+s[j]+um;      s[j]:=l mod 10;      um:=l div 10;     end;   end;   B:=A;   B[length(Min)]:=B[length(Min)]-1;    FillChar(C,SizeOf(C),0 Re: I've found the error. But I still get WA. Please help me! (+) My new program:   Program t1165;   Const MaxD=400;   Type  ResType=array[1..MaxD]of integer;   Var A        :string[250];     MinS,Cur :string[250];     i,mfrom  :integer;     GetOk    :boolean;     wor      :array[1..251]of integer;   Procedure MakeWor(S:string); Var i,j,p :integer;  begin   FillChar(wor,SizeOf(wor),0);   for i:=length(S) downto 1 do begin    val(S[i],j,p);    wor[length(S)-i+1]:=j;   end;  end;   Function ConvertInStr(len:integer):string; var i     :integer;     l,ans :string[250];  begin   ans:='';   for i:=1 to len do begin    str(wor[i],l);    ans:=l+ans;   end;   ConvertInStr:=ans;  end;   Function GetPred(S:string):string; var i,j,flag :integer;  begin   flag:=0;   MakeWor(S);   wor[1]:=wor[1]-1;   if wor[1]=-1 then begin    for j:=2 to 251 do     if wor[j]>0 then break;    wor[j]:=wor[j]-1;    if wor[j]=0 then flag:=-1;    for i:=1 to j-1 do wor[i]:=9;   end;   GetPred:=ConvertInStr(length(S)+flag);  end;   Function GetNext(S:string):string; var i,j,flag :integer;  begin   flag:=0;   MakeWor(S);   wor[1]:=wor[1]+1;   for i:=1 to 251 do    if wor[i]>9 then begin     wor[i+1]:=wor[i+1]+(wor[i] div 10);     wor[i]:=wor[i] mod 10;    end;   if wor[length(S)+1]>0 then flag:=1;   GetNext:=ConvertInStr(length(S)+flag);  end;   Function GetNextXX(StrX:string):string; Var i,j,p :integer;     ans,l :string[250];     mas   :array[1..251]of byte;  begin   FillChar(mas,SizeOf(mas),0);   for i:=length(StrX) downto 1 do begin    val(StrX[i],j,p);    mas[length(StrX)-i+1]:=j;   end;   ans:='';   mas[1]:=mas[1]+1;   for i:=1 to 251 do    if mas[i]>9 then begin     mas[i+1]:=mas[i+1]+(mas[i] div 10);     mas[i]:=mas[i] mod 10;    end;   for i:=1 to length(StrX) do begin    str(mas[i],l);    ans:=l+ans;   end;   GetNextXX:=ans;  end;   Function GetMin(from:integer):string; Var BeginStr   :string[250];     MaskStr    :string[250];     second     :string[250];     Next       :string[250];     CurPos     :integer;     MaskBegin  :integer;     i,j,t      :integer;     len        :integer;     ok,yes     :boolean;  begin   BeginStr:=copy(A,1,from);   MaskStr:=GetNextXX(BeginStr);   MaskBegin:=from+1;   if A[MaskBegin]='0' then begin    GetOk:=false;    exit;   end;   if MaskStr<BeginStr then    MaskBegin:=MaskBegin+1;   len:=length(MaskStr);   for i:=MaskBegin-1 to length(A) do begin    ok:=true;    for j:=1 to len do begin     if i+j>length(A) then break;     if A[i+j]<>MaskStr[j] then ok:=false;    end;    if ok then begin     yes:=true;     second:=copy(A,from+1,i+len-from);     if i+j>length(A) then      for t:=j to len do second:=second+MaskStr[t];     CurPos:=i+len+1;     if Pos(BeginStr,GetPred(second))=0 then yes:=false;     Next:=second;     While True do begin      Next:=GetNext(Next);      for t:=CurPos to CurPos+length(Next)-1 do begin       if t>length(A) then break;       if A[t]<>Next[t-CurPos+1] then yes:=false;      end;      CurPos:=CurPos+length(Next);      if CurPos>length(A) then break;     end;     if yes then begin      GetOk:=true;      GetMin:=GetPred(second);      exit;     end;    end;   end;   GetOk:=false;  end;   Procedure MakeResult; Var i,j,k   :integer;     um,l    :integer;     A,B,C,S :ResType;  begin   FillChar(A,SizeOf(A),0);   for i:=1 to length(MinS) do begin    val(MinS[i],k,j);    A[length(MinS)+1-i]:=k;   end;   FillChar(S,SizeOf(S),0);   for i:=1 to length(MinS)-1 do begin    FillChar(B,SizeOf(B),0);    B[i]:=9;    FillChar(C,SizeOf(C),0);    um:=0;    for j:=1 to MaxD do begin      l:=b[j]*i+um;      c[j]:=l mod 10;      um:=l div 10;     end;    um:=0;    for j:=1 to MaxD do begin      l:=c[j]+s[j]+um;      s[j]:=l mod 10;      um:=l div 10;     end;   end;   B:=A;   B[length(MinS)]:=B[length(MinS)]-1;    FillChar(C,SizeOf(C),0); A test for you (+) Try this test case : 09910 The correct answer is 2618 (909,910) By the way, this is the test that xyz gave me when I asked for some help on this problem. It is often useful to watch webboard for the problem you can't get AC for - if you did this you would find this test case. Hope you'll get AC! Good luck! Re: Thank you! But I've got AC already. > Try this test case : 09910 > The correct answer is 2618 (909,910) > By the way, this is the test that xyz gave me when I asked for some > help on this problem. It is often useful to watch webboard for the > problem you can't get AC for - if you did this you would find this > test case. > Hope you'll get AC! > Good luck!  |