Generate subsets · Compiler

Generate subsets

List every subset of a menu of distinct toppings. Number the toppings from 0 in input order. Give each subset a number by adding 2 raised to i for every included topping index i. List subsets in increasing order of that number.

Input
The first token is the number of toppings n (0 to 8). The next n tokens are distinct names of 1 to 12 lowercase ASCII letters each.
Output
Print one subset per line, starting with EMPTY for the empty subset. Within each other subset print the selected names in input order, separated by spaces.

Compiler Explorer runs your code when you run or check it.

Loading your exercise draft…