home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Usenet 1994 October
/
usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso
/
unix
/
volume17
/
contest-prog
/
part02
/
prob13.txt
< prev
next >
Wrap
Text File
|
1989-02-06
|
1KB
|
36 lines
Problem 13: Binary-binary.
Mathematicians refer to addition and subtraction as binary
operations. Since computer scientists like to take things much
farther than they were intended, you are going to write a
binary binary calculator.
This calculator program will accept infix expressions involving
only + and - and unsigned binary integers. No parentheses or
other operations will be present. You must compute the value
of the expression and display the result in binary. Negative
results should be printed with a leading minus sign.
Data considerations:
Input will consist of an unspecified number of expressions,
one per line; end-of-file will indicate the end of data. Each
expression may contain leading or embedded blanks; however, no
number will contain embedded blanks.
A totally blank line should evoke an output of '0'.
No expression will contain more than 80 characters. The
expression values are to be computed left-to-right. No
number or intermediate value will require more than 15 bits
of precision. Output should start in column 1 of the
output file, one result per line, with no leading zeroes.
Example:
the input expression: 110+11- 1 +100
results in the output
1100
the input expression: 1100 - 11000+111-10
results in the output
-111
the input expression: <a blank line>
results in the output
0