ENG  RUS Timus Online Judge
Online Judge
Problems
Authors
Online contests
Site news
Webboard
Problem set
Submit solution
Judge status
Guide
Register
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

## Discussion of Problem 1406. Next Number

WA#9
Posted by Evgeniy 7 Jan 2007 19:27
What it is it? My program overcome all my tests,but system(TIMUS) written me about WA#9!
WHY?
Re: WA#9
Posted by williamljb 14 May 2009 11:33
me too!
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
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.
Re: WA#9
Posted by Viktor Krivoshchekov`~ 16 Feb 2019 16:38
1000
ans -1