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 1140. Swamp Incident

Show all messages Hide all messages

var
  x,y,z:integer;
  n,i,j:integer;
  na,nx,ny,nz,nj:integer;
  c:char;
begin
  x:=0;y:=0;z:=0;
  readln(n);
  for i:=1 to n do
  begin
    readln(c,j);
    case upcase(c) of
      'X':inc(x,j);
      'Y':inc(y,j);
      'Z':inc(z,j);
    end;
  end;
  nx:=0;ny:=y+x;nz:=z-x;nj:=abs(nx)+abs(ny)+abs(nz);
  if (ny=0) or (nz=0) then na:=1 else na:=2;
  x:=nx+ny;y:=0;z:=nz+ny;j:=abs(x)+abs(y)+abs(z);
  if (x=0) or (z=0) then n:=1 else n:=2;
  if nj>j then
  begin
    na:=n;nx:=x;ny:=y;nz:=z;nj:=j;
  end;
  x:=nx-nz;y:=ny+nz;z:=0;j:=abs(x)+abs(y)+abs(z);
  if (x=0) or (y=0) then n:=1 else n:=2;
  if nj>j then
  begin
    na:=n;nx:=x;ny:=y;nz:=z;nj:=j;
  end;
  writeln(na);
  if nx<>0 then writeln('X ',-nx);
  if ny<>0 then writeln('Y ',-ny);
  if nz<>0 then writeln('Z ',-nz);
end.
Try this simple test: 0. The answer should be 0, but yours is 1. Maigo Akisame (maigoakisame@yahoo.com.cn) 17 Jul 2004 12:51
Your test is incorrect! Saturn (HUS) 18 Jul 2004 00:55
Your test is incorrect because n>0!
Try this test:
3
X 1
Z 1
Y -1
Correct output : 0
Your output : 1