Why I got WA
Posted by
qwt 20 Mar 2002 18:41
const
way:Array[1..8] of byte=(8,7,6,5,1,2,3,4);
list:array[1..8,0..3] of byte=(
(2,2,4,0),(1,3,0,0),(1,4,0,0),(0,0,0,0),
(1,1,0,0),(2,2,5,0),(2,3,6,0),(3,4,5,7));
tt:string='ABCDEFGH';
maxn=10000;
var
a:Array[1..8] of integer;
i,j,k,p,q,r,tot:longint;
s:array[1..maxn] of string[3];
begin
fillchar(s,sizeof(s),0);
tot:=0;
fillchar(a,sizeof(A),0);
for i:=1 to 8 do read(a[i]);readln;
if a[1]+a[3]+a[6]+a[8]<>a[2]+a[4]+a[5]+a[7] then begin writeln
('IMPOSSIBLE');halt;end;
for i:=1 to 7 do begin
p:=way[i];
for j:=1 to list[p,0] do
if a[p]>0 then begin
if a[p]<=a[list[p,j]] then begin
for k:=1 to a[p] do begin
inc(tot);
s[tot]:=tt[p]+tt[list[p,j]]+'-';
end;
dec(a[list[p,j]],a[p]);
a[p]:=0;
end else begin
q:=list[p,j];
for k:=1 to a[q] do begin
inc(tot);s[tot]:=tt[p]+tt[q]+'-';
end;
dec(a[p],a[q]);a[q]:=0;
end;
end;
if (a[p]>0) then begin
q:=way[i+1];r:=way[i+2];
for k:=1 to a[p] do begin
inc(tot);s[tot]:=tt[q]+tt[r]+'+';
inc(tot);s[tot]:=tt[p]+tt[q]+'-';
end;
a[q]:=a[p];a[p]:=0;inc(a[r],a[q]);
end;
end;
for i:=1 to tot do writeln(s[i]);
end.