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 1007. Code Words

Why does my program get "WA"?
Posted by Sam Koo 8 Apr 2002 19:51
program u1007;

var
  n,u,l,v,uu :integer;
  a,b :array[1..4001] of char;
  ch :char;
  okay :boolean;
procedure judgeit;

var
  u:integer;
  k :longint;

begin
  k:=0;   okay:=false;
  for u:=1 to n do if b[u]='1' then k:=k+u;
  if k mod (n+1)=0 then begin
    for u:=1 to n do write(b[u]);
    writeln;  okay:=true;
  end;
end;


procedure work;
begin
  if l<n then begin
     for u:=0 to l do begin
          for v:=1 to u do b[v]:=a[v];
          b[u+1]:='0';
          for v:=u+1 to l do b[v+1]:=a[v];
          judgeit;
          if okay then exit;
          b[u+1]:='1';
          judgeit;
          if okay then exit;
        end;
      end else if l>n then begin
        for u:=1 to l do begin
          for v:=1 to u-1 do b[v]:=a[v];
          for v:=u+1 to l do b[v-1]:=a[v];
          judgeit;
          if okay then exit;
        end;
      end else begin
        b:=a;
        judgeit;
        if okay then exit;
        for u:=1 to l do if b[u]='1' then begin
          b[u]:='0';
          judgeit;
          b[u]:='1';
          if okay then exit;
        end;
      end;
end;



begin
{  assign(input,'u1007.in');
  reset(input);}
  readln(n);
  while not eof(input) do begin
    read(ch);
    if not (ch in ['0','1']) then begin
      work;
      l:=0;
      readln;
    end else begin inc(l); a[l]:=ch; end;
  end;
{  close(input);}
end.