Back
Close
  • 75

Learning Opportunities

This puzzle can be solved using the following concepts. Practice using these concepts and improve your skills.

Statement

 Goal

Write a program that, given an expression composed of finite sets, unions (U), intersections (I), differences (-) and parentheses, outputs the values ​​contained in the resulting set.

A set can be written with braces { }, or brackets [ ]. It contains whole numbers, positive or negative, separated by semicolons ;.

• If the set is written with braces, then it contains only the values ​​between braces, e.g. {4;3;-2} contains only the values ​​4, 3 and -2.

• If the set is written with brackets, then it is an interval, e.g. [-2;2] contains the values ​​-2, -1, 0, 1 and 2.

Pay attention to the orientation of the brackets: the set can also be noted [a;b[ for example, in this case it contains all the values ​​of a included to b excluded. You will encounter all the variants: ]a;b[, ]a;b], [a;b[ and [a;b].

Sets' endpoints with braces are not necessarily ordered, while sets' endpoints with brackets are always ordered.

Pay attention to parentheses, which prioritize some operations over others. When no parentheses are present, all operators (U, I and -) have the same precedence and are evaluated from left to right.
Input
Line 1: A string representing an expression consisting of N sets.
Output
Line 1: All the numbers contained in the resulting set, ordered and separated by spaces, or EMPTY if the resulting set is empty.
Constraints
1 ≤ N ≤ 10
-100 ≤ numbers ≤ 100
Example
Input
{2;3;1}
Output
1 2 3

A higher resolution is required to access the IDE