Set
InterviewTime limit1.5sMemory limit4 MB
Maintain a set of integers 1 to 20 under add, remove, toggle, check, all, and empty, and print each check result.
- Level
Easy3 of 10
- Topics
- Bit manipulation, Implementation
- Solved
- No attempts yet
Problem
You start with an empty set . Write a program that performs the following operations.
add x: adds to . If is already in , the operation is ignored.remove x: removes from . If is not in , the operation is ignored.check x: prints 1 if is in , and 0 otherwise.toggle x: removes from if is in , and adds otherwise.all: replaces with .empty: replaces with the empty set.
For add, remove, check and toggle, the argument satisfies .
Input
The first line contains the number of operations ().
Each of the next lines contains one operation. It is one of the six operations described above, and an operation that takes an argument has its name and separated by a single space.
Output
For every check operation, print its result on its own line, in the order the operations are given.
If there is no check operation, print nothing.