|  | 
|  | 
| back to board | WA#9 What it is it? My program overcome all my tests,but system(TIMUS) written me about WA#9!WHY?
Re: WA#9 me too!any ideas, please send to:
 williamm2006@126.com
 
 thanks!
 
 program p1406;
 var
 a:array[1..2000]of longint;
 ch:char;
 i,j,k,n,m:longint;
 begin
 while not eof(input) do
 begin
 read(ch);
 if ch in['0'..'9']
 then begin
 inc(n);
 a[n]:=ord(ch)-48;
 end;
 end;
 for i:=n downto 1 do
 if a[i]>0
 then break;
 if((i=1)and(a[i]=0))or(n=1)
 then begin
 writeln(-1);
 halt;
 end;
 j:=i-1;m:=a[i]-1;a[i]:=0;
 for j:=i-1 downto 1 do
 if a[j]<>9
 then break;
 if(j=1)and(a[j]=9)
 then begin
 writeln(-1);
 halt;
 end;
 inc(a[j]);
 for i:=j+1 to n do
 begin
 inc(m,a[i]);
 a[i]:=0;
 end;
 i:=n;
 while m>0 do
 begin
 if m>=9
 then a[i]:=9
 else a[i]:=m;
 dec(i);
 dec(m,9);
 end;
 for i:=1 to n do
 write(a[i]);
 writeln;
 end.
 | 
 | 
|