Cartesian products of lists P68155


Statement
 

pdf   zip

html

René Descartes (31 March 1596 — 11 February 1650) was a French writer, philosopher and mathematician who spent most of his adult life in the Dutch Republic. In this problem, you are asked to compute the Cartesian product of lists of integer numbers. For instance, the cartesian product of [[1,2,3],[4,5]] is [[1,4],[1,5],[2,4],[2,5],[3,4],[3,5]].

Input

Input consists of several lists of sublists of integer numbers, each on a line. Every list ends with a dot. Sublists are separated with bars. Numbers are separated with commas. Each list and each sublist has, at least, one element.

Output

For every list, print its Cartesian product following the format of the sample output.

Public test cases
  • Input

    1,2,3|4,5.
    1,2,3|4,5|6,7.
    100|100,200,300.
    2|2.
    5,2|7,8|2|6|9,8.
    66.
    

    Output

    1,4|1,5|2,4|2,5|3,4|3,5.
    1,4,6|1,4,7|1,5,6|1,5,7|2,4,6|2,4,7|2,5,6|2,5,7|3,4,6|3,4,7|3,5,6|3,5,7.
    100,100|100,200|100,300.
    2,2.
    5,7,2,6,9|5,7,2,6,8|5,8,2,6,9|5,8,2,6,8|2,7,2,6,9|2,7,2,6,8|2,8,2,6,9|2,8,2,6,8.
    66.
    
  • Information
    Author
    Jordi Petit
    Language
    English
    Official solutions
    C++
    User solutions
    C++ Python