type mystr=string[80];
var s1,s2,s,p:mystr;
x,y,k:integer;
function search(var ch:char;s:mystr):integer;
var i,k : integer;
begin
k:=0;
for i:=length(s) downto 1 do begin
if s[i]='(' then inc(k);
if s[i]=')' then dec(k);
if (k=0) and (s[i] in ['+','-','*']) then begin
search:=i; ch:=s[i]; exit;
end;
end;
search:=0;
end;
function calc(s:mystr):longint;
var i,j,k,c,l: integer;
ok:boolean;
ch: char;
begin
l:=length(s);
k:=0;
ok:=true;
for i:=1 to l do begin
if s[i]='(' then inc(k);
if s[i]=')' then dec(k);
if (i>1) and (i<l) and (k=0) then ok:=false;
end;
if ok and (s[1]='(') and (s[l]=')') then begin
calc:=calc(copy(s,2,l-2));
exit;
end else begin
k:=search(ch,s);
if k>0 then begin
case ch of
'+': calc:=calc(copy(s,1,k-1))+calc(copy(s,k+1,l-k));
'-': calc:=calc(copy(s,1,k-1))-calc(copy(s,k+1,l-k));
'*': calc:=calc(copy(s,1,k-1))*calc(copy(s,k+1,l-k));
end;
exit;
end;
end;
val(s,k,l);
calc:=k;
end;
procedure find(k:integer);
begin
if k>length(s) then begin
if x=calc(s) then p:=s;
end else
if s[k]=' ' then begin
s[k]:='+'; find(k+1);
s[k]:='-'; find(k+1);
s[k]:='*'; find(k+1);
s[k]:=' ';
end
else find(k+1);
end;
begin
assign(input, 'input.txt'); reset(input);
assign(output, 'output.txt'); rewrite(output);
p:='';
readln(s);
while pos(' ',s)>0 do delete(s,pos(' ',s),1);
if s[length(s)]=' ' then delete(s,1,length(s)-1);
if pos('= ',s)>0 then delete(s,pos('= ',s)+1,1);
if pos(' =',s)>0 then delete(s,pos(' =',s),1);
if s[1]=' ' then delete(s,1,1);
k:=pos('=',s);
val(copy(s,1,k-1),x,y);
s:=copy(s,k+1,length(s)-k);
find(1);
if p>'' then write(x,'=',p) else write(-1);
end.
|