Tell me why??????????? WA!!!!!!! Posted by Levin 24 Jun 2002 22:36 type tnode=array[1..500] of integer; var a,b,c,r:tnode; i,j,k,v,n,tb,tc,tr:integer; ss:string; procedure sub; var i:integer; begin dec(c[1]); i:=1; while c[i]=-1 do begin dec(c[i+1]); c[i]:=9; inc(i); end; if (tc>1)and(c[tc]=0) then dec(tc); end; procedure add; var i:integer; begin inc(c[1]); i:=1; while c[i]=10 do begin inc(c[i+1]); c[i]:=0; inc(i); end; if c[tc+1]>0 then inc(tc); end; function equal(x,y,k:integer):boolean; var i:Integer; begin equal:=false; for i:=0 to k-1 do if c[i+x]<>a[y+i] then exit; equal:=true; end; function check:boolean; begin check:=false; c:=b;tc:=tb; k:=j+1; while k<=n do begin sub; if (tc=1)and(c[1]=0) then exit; if k+tc-1<=n then begin if equal(1,k,tc) then else exit; inc(k,tc); end else begin if equal(1,k,n-k+1) then else exit; k:=n+1; end; end; c:=b;tc:=tb; k:=j-i; while k>0 do begin add; if k-tc+1>0 then begin if equal(1,k-tc+1,tc) then else exit; dec(k,tc); end else begin if equal(tc-k+1,1,k) then else exit; k:=0; end; end; check:=true; end; procedure wish(k:integer); var i:integer; begin if tb>tr then exit; if tb<tr then begin r:=b;tr:=tb;v:=k; exit; end; for i:=tb downto 1 do begin if b[i]>r[i] then exit; if b[i]<r[i] then begin r:=b;tr:=tb;v:=k; exit; end; end; if k<v then v:=k; end; procedure compute; begin if tr=1 then begin tc:=1;c[1]:=r[1]+v; exit; end; fillchar(c,sizeof(c),0); for i:=1 to tr-1 do begin j:=i;k:=i; while j>0 do begin inc(c[k],j mod 10); if c[k]>9 then begin inc(c[k+1]);dec(c[k],10);end; j:=j div 10; inc(k); end; end; if c[k]>0 then tc:=k else tc:=k-1; k:=0; for i:=1 to tc do begin c[i]:=c[i]*9+k; k:=0; while c[i]>9 do begin inc(k); dec(c[i],10); end; end; if k>0 then begin inc(tc);c[tc]:=k;end; j:=tr; dec(r[tr]); while (tr>0)and(r[tr]=0) do dec(tr); for i:=1 to tr do begin inc(c[i],r[i]*j); while c[i]>9 do begin inc(c[i+1]); dec(c[i],10); end; end; i:=tr+1; while c[i]>9 do begin while c[i]>9 do begin inc(c[i+1]); dec(c[i],10); end; inc(i); end; if i>tc then tc:=i; if c[tc]=0 then dec(tc); inc(c[1],v+1); i:=1; while (c[i]>9)or(c[i]<0) do begin while c[i]>9 do begin inc(c[i+1]); dec(c[i],10); end; while c[i]<0 do begin dec(c[i+1]); inc(c[i],10); end; inc(i); end; if i>tc then tc:=i; if c[tc]=0 then dec(tc); end; begin assign(input,''); reset(input); readln(ss); while ss[1]=' ' do delete(ss,1,1); while ss[length(ss)]=' ' do delete(ss,length(ss),1); n:=length(ss); fillchar(a,sizeof(a),0); for i:=1 to n do a[i]:=ord(ss[n+1-i])-48; tr:=500; fillchar(b,sizeof(b),0); for i:=1 to n-1 do begin tb:=i; for j:=n downto n-i+1 do if j<i then break else if a[j]>0 then begin move(a[j-i+1],b[1],i*2); if check then wish(j-n); end; if tr<500 then break; end; if tr=500 then if a[n]=0 then begin tr:=n+1; move(a[1],r[1],n*2); r[tr]:=1; v:=1; end else begin tr:=n; move(a[1],r[1],n*2); v:=0; end; fillchar(c,sizeof(c),0); for i:=n-1 downto 1 do if a[i]>0 then begin tc:=n-i; move(a[i+1],c[1],tc*2); add; if tc>n-i then
Re: Tell me why??????????? WA!!!!!!! Posted by Yang Yi 15 Oct 2002 15:32 > type tnode=array[1..500] of integer; > var a,b,c,r:tnode; > i,j,k,v,n,tb,tc,tr:integer; > ss:string; > > procedure sub; > var i:integer; > begin > dec(c[1]); > i:=1; > while c[i]=-1 do > begin > dec(c[i+1]); > c[i]:=9; > inc(i); > end; > if (tc>1)and(c[tc]=0) then dec(tc); > end; > > procedure add; > var i:integer; > begin > inc(c[1]); > i:=1; > while c[i]=10 do > begin > inc(c[i+1]); > c[i]:=0; > inc(i); > end; > if c[tc+1]>0 then inc(tc); > end; > > function equal(x,y,k:integer):boolean; > var i:Integer; > begin > equal:=false; > for i:=0 to k-1 do > if c[i+x]<>a[y+i] then exit; > equal:=true; > end; > > function check:boolean; > begin > check:=false; > c:=b;tc:=tb; > k:=j+1; > while k<=n do > begin > sub; > if (tc=1)and(c[1]=0) then exit; > if k+tc-1<=n then > begin > if equal(1,k,tc) then else exit; > inc(k,tc); > end else > begin > if equal(1,k,n-k+1) then else exit; > k:=n+1; > end; > end; > > c:=b;tc:=tb; > k:=j-i; > while k>0 do > begin > add; > if k-tc+1>0 then > begin > if equal(1,k-tc+1,tc) then else exit; > dec(k,tc); > end else > begin > if equal(tc-k+1,1,k) then else exit; > k:=0; > end; > end; > check:=true; > end; > > procedure wish(k:integer); > var i:integer; > begin > if tb>tr then exit; > if tb<tr then > begin > r:=b;tr:=tb;v:=k; > exit; > end; > for i:=tb downto 1 do > begin > if b[i]>r[i] then exit; > if b[i]<r[i] then > begin > r:=b;tr:=tb;v:=k; > exit; > end; > end; > if k<v then v:=k; > end; > > procedure compute; > begin > if tr=1 then > begin > tc:=1;c[1]:=r[1]+v; > exit; > end; > > fillchar(c,sizeof(c),0); > for i:=1 to tr-1 do > begin > j:=i;k:=i; > while j>0 do > begin > inc(c[k],j mod 10); > if c[k]>9 then begin inc(c[k+1]);dec(c[k],10);end; > j:=j div 10; > inc(k); > end; > end; > if c[k]>0 then tc:=k else tc:=k-1; > > k:=0; > for i:=1 to tc do > begin > c[i]:=c[i]*9+k; > k:=0; > while c[i]>9 do > begin > inc(k); > dec(c[i],10); > end; > end; > if k>0 then begin inc(tc);c[tc]:=k;end; > > j:=tr; > dec(r[tr]); > while (tr>0)and(r[tr]=0) do dec(tr); > for i:=1 to tr do > begin > inc(c[i],r[i]*j); > while c[i]>9 do > begin > inc(c[i+1]); > dec(c[i],10); > end; > end; > i:=tr+1; > while c[i]>9 do > begin > while c[i]>9 do > begin > Re: Tell me why??????????? WA!!!!!!! Posted by Yang Yi 15 Oct 2002 15:34 Try this text: 99 I think the answer is 169. 86 87 88 8(9 9)0 Your output is 188. |