Sort each decimal by the round it is removed from the Cantor middle-third process, placing numbers that never vanish last.
Medium5MathSortingNo attempts yetTime limit5sMemory limit512 MBThere is a pool of numbers, each of them a decimal fraction from the interval (0,1). In the first round the middle third of (0,1) disappears, and every number that falls into it drops out of the pool. In each later round the middle third of every remaining interval disappears. Round 1 removes [1/3,2/3], round 2 removes [1/9,2/9] and [7/9,8/9], and so on. The endpoints of a removed interval are removed with it.
Sort the pool by the round in which each number disappears. Numbers that never disappear go last. When two numbers disappear in the same round, print the smaller one first. When the same number occurs several times in the pool, print it once for each occurrence.
The first line contains T, the number of test cases. Each test case starts with a line holding an integer N, followed by N numbers, one per line. Each number starts with "0." and continues with one or more decimal digits. Every number is greater than zero and has no trailing zero.
For each test case, print the line "Case #x:", where x is the number of the test case, starting with 1. After that line, print the N numbers of that pool, one per line, in the order they disappear. Print each number exactly as it was written in the input.
In case #1 of the sample, 0.5 disappears in round 1 because it falls into [1/3,2/3]. After round 1 two intervals are left, (0,1/3) and (2/3,1), and 0.12 disappears in round 2 because it falls into [1/9,2/9]. In case #2 neither 0.1 nor 0.9 ever disappears, so both come last, the smaller one first.