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

Discussion of Problem 1683. Fridge

Help Wa3
Posted by Rabidstorm 2 Apr 2009 14:18
My program Wa3
This is my program:
program Ural683;

var
  a,m,n:longint;
  k:array[0..50]of longint;

begin
  readln(n);
  m:=1;
  k[0]:=n;
  while k[m-1]<>0 do
    begin
      k[m]:=k[m-1]shr 1;
      inc(m);
    end;
  m:=0;
  a:=1;
  while a<n do
    begin
      inc(m);a:=a shl 1;
    end;
  writeln(m);
  for a:=1 to m do
    if k[a]=0 then write(1,' ')
    else write(k[a],' ');
end.
Who can help me?

Edited by author 02.04.2009 14:18
Re: Help Wa3
Posted by Rabidstorm 2 Apr 2009 19:46
Now I am AC!!!
program Ural683;

var
  a,m,n:longint;
  k:array[0..50]of longint;

begin
  readln(n);
  m:=0;
  while n<>1 do
    begin
      inc(m);
      n:=n-n shr 1;
      k[m]:=n;
    end;
  writeln(m);
  for a:=1 to m do
    write(k[a],' ');
end.