ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Common Board

Diving 7. Why WA.
Posted by I am david. Tabo. 2 Mar 2003 11:46
const inp='gnoms.tst';
      out='gnoms.ans';

var sol,i,j,k,l,m,n:integer;
    u:array [1..50] of char;
    a,b:array [1..50] of byte;

procedure Change;
  begin
    for i:=1 to n do
      val (u[i],a[i],l);
  end;


procedure readdata;
  begin
{    assign (input,inp);
    reset (input);}
    while not (eoln) do
      begin
        inc (n);
        read ({input,}u[n]);
      end;
    readln {(input)};
{    close (input);}
    Change;
    if (n=1)and(a[1]<7) then
      begin
        writeln (a[1]);
        halt;
      end;
  end;

procedure print;
var nn:longint;
  begin
    nn:=0;
    for l:=1 to n do
      if a[l]=0 then
        inc (nn)
      else
        sol:=a[l];
    if (n-nn=1)or(n-nn=0) then
      begin
        writeln (sol);
        halt;
      end;
  end;

procedure solve;
  begin
    while 0=0 do
      begin
        if a[1]>=7 then
          begin
            b[1]:=a[1]-(7*(a[1] div 7));
            for j:=2 to n do
              b[j]:=a[j];
            a:=b;
          end
        else
          if a[1]<>0 then
            begin
              b[1]:=(a[1]*10+a[2])-(7*((a[1]*10+a[2])div 7));
              for j:=2 to n do
                b[j]:=a[j+1];
              a:=b;
            end
          else
            begin
              for k:=1 to n do
                b[k]:=b[k+1];
              a:=b;
            end;
        print;
      end;
  end;

begin
  readdata;
  solve;
end.
I got AC
Posted by I am david. Tabo. 2 Mar 2003 16:43
> const inp='gnoms.tst';
>       out='gnoms.ans';
>
> var sol,i,j,k,l,m,n:integer;
>     u:array [1..50] of char;
>     a,b:array [1..50] of byte;
>
> procedure Change;
>   begin
>     for i:=1 to n do
>       val (u[i],a[i],l);
>   end;
>
>
> procedure readdata;
>   begin
> {    assign (input,inp);
>     reset (input);}
>     while not (eoln) do
>       begin
>         inc (n);
>         read ({input,}u[n]);
>       end;
>     readln {(input)};
> {    close (input);}
>     Change;
>     if (n=1)and(a[1]<7) then
>       begin
>         writeln (a[1]);
>         halt;
>       end;
>   end;
>
> procedure print;
> var nn:longint;
>   begin
>     nn:=0;
>     for l:=1 to n do
>       if a[l]=0 then
>         inc (nn)
>       else
>         sol:=a[l];
>     if (n-nn=1)or(n-nn=0) then
>       begin
>         writeln (sol);
>         halt;
>       end;
>   end;
>
> procedure solve;
>   begin
>     while 0=0 do
>       begin
>         if a[1]>=7 then
>           begin
>             b[1]:=a[1]-(7*(a[1] div 7));
>             for j:=2 to n do
>               b[j]:=a[j];
>             a:=b;
>           end
>         else
>           if a[1]<>0 then
>             begin
>               b[1]:=(a[1]*10+a[2])-(7*((a[1]*10+a[2])div 7));
>               for j:=2 to n do
>                 b[j]:=a[j+1];
>               a:=b;
>             end
>           else
>             begin
>               for k:=1 to n do
>                 b[k]:=b[k+1];
>               a:=b;
>             end;
>         print;
>       end;
>   end;
>
> begin
>   readdata;
>   solve;
> end.
Jeje, there's a method which is O(n), with n numbers given
Posted by Miguel Angel 3 Mar 2003 01:46
> const inp='gnoms.tst';
>       out='gnoms.ans';
>
> var sol,i,j,k,l,m,n:integer;
>     u:array [1..50] of char;
>     a,b:array [1..50] of byte;
>
> procedure Change;
>   begin
>     for i:=1 to n do
>       val (u[i],a[i],l);
>   end;
>
>
> procedure readdata;
>   begin
> {    assign (input,inp);
>     reset (input);}
>     while not (eoln) do
>       begin
>         inc (n);
>         read ({input,}u[n]);
>       end;
>     readln {(input)};
> {    close (input);}
>     Change;
>     if (n=1)and(a[1]<7) then
>       begin
>         writeln (a[1]);
>         halt;
>       end;
>   end;
>
> procedure print;
> var nn:longint;
>   begin
>     nn:=0;
>     for l:=1 to n do
>       if a[l]=0 then
>         inc (nn)
>       else
>         sol:=a[l];
>     if (n-nn=1)or(n-nn=0) then
>       begin
>         writeln (sol);
>         halt;
>       end;
>   end;
>
> procedure solve;
>   begin
>     while 0=0 do
>       begin
>         if a[1]>=7 then
>           begin
>             b[1]:=a[1]-(7*(a[1] div 7));
>             for j:=2 to n do
>               b[j]:=a[j];
>             a:=b;
>           end
>         else
>           if a[1]<>0 then
>             begin
>               b[1]:=(a[1]*10+a[2])-(7*((a[1]*10+a[2])div 7));
>               for j:=2 to n do
>                 b[j]:=a[j+1];
>               a:=b;
>             end
>           else
>             begin
>               for k:=1 to n do
>                 b[k]:=b[k+1];
>               a:=b;
>             end;
>         print;
>       end;
>   end;
>
> begin
>   readdata;
>   solve;
> end.
n digits
Posted by Miguel Angel 3 Mar 2003 01:49
> > const inp='gnoms.tst';
> >       out='gnoms.ans';
> >
> > var sol,i,j,k,l,m,n:integer;
> >     u:array [1..50] of char;
> >     a,b:array [1..50] of byte;
> >
> > procedure Change;
> >   begin
> >     for i:=1 to n do
> >       val (u[i],a[i],l);
> >   end;
> >
> >
> > procedure readdata;
> >   begin
> > {    assign (input,inp);
> >     reset (input);}
> >     while not (eoln) do
> >       begin
> >         inc (n);
> >         read ({input,}u[n]);
> >       end;
> >     readln {(input)};
> > {    close (input);}
> >     Change;
> >     if (n=1)and(a[1]<7) then
> >       begin
> >         writeln (a[1]);
> >         halt;
> >       end;
> >   end;
> >
> > procedure print;
> > var nn:longint;
> >   begin
> >     nn:=0;
> >     for l:=1 to n do
> >       if a[l]=0 then
> >         inc (nn)
> >       else
> >         sol:=a[l];
> >     if (n-nn=1)or(n-nn=0) then
> >       begin
> >         writeln (sol);
> >         halt;
> >       end;
> >   end;
> >
> > procedure solve;
> >   begin
> >     while 0=0 do
> >       begin
> >         if a[1]>=7 then
> >           begin
> >             b[1]:=a[1]-(7*(a[1] div 7));
> >             for j:=2 to n do
> >               b[j]:=a[j];
> >             a:=b;
> >           end
> >         else
> >           if a[1]<>0 then
> >             begin
> >               b[1]:=(a[1]*10+a[2])-(7*((a[1]*10+a[2])div 7));
> >               for j:=2 to n do
> >                 b[j]:=a[j+1];
> >               a:=b;
> >             end
> >           else
> >             begin
> >               for k:=1 to n do
> >                 b[k]:=b[k+1];
> >               a:=b;
> >             end;
> >         print;
> >       end;
> >   end;
> >
> > begin
> >   readdata;
> >   solve;
> > end.
I have more beauty solution mail me aidin_n7@hotmail.com
Posted by Locomotive 8 Mar 2003 17:05