4
Your task is to write a program to perform set operations. The operations and arguments are taken from command line in the format program operation [argument]
. There are four operations:
- 1: clears the set. no arguments. exit code 0.
- 2 integer: adds the
integer
into the set. exit code 0. - 3 integer: removes the
integer
from the set. exit code 0. - 4 integer: queries the set for
integer
. exit code 0 if integer exists or 1 otherwise.
The integer is a 64-bits integer. Shortest program wins. You can, of course, use a temporary file. However, watch out the space and time limit.
Example:
$ program 1 ; echo $?
0
$ program 2 10 ; echo $?
0
$ program 4 10 ; echo $?
0
$ program 3 10 ; echo $?
0
$ program 4 10 ; echo $?
1
$ program 2 10 ; echo $?
0
$ program 1 ; echo $?
0
$ program 4 10 ; echo $?
1
@Joey. Yes. That's why you should use a file. – Alexandru – 2011-02-26T00:11:00.067
Your 4th test assert an exit code of
1
which is not according to the specification (where3
would always return0
). – Joey – 2011-02-26T16:30:12.837@Joey: thank you. I missed that. – Alexandru – 2011-02-26T16:38:55.400