A ground station receives a garbled telemetry burst that should have encoded a pair of decimal sensor readings — written originally as two numbers separated by a comma, such as 1.2 and 34 — but a transmission fault stripped every non-digit character (no comma, no decimal points), leaving only the concatenated digits.
A numeral recovered from a nonempty block of digits b is a valid plain integer reading when b has length 1, or when b has length greater than 1 and its first digit is not '0'. A numeral recovered by inserting a decimal point strictly inside b, splitting it into a nonempty integer part p followed by a nonempty fractional part q (so p concatenated with q equals b), is a valid decimal reading when p is itself a valid plain integer under the rule above, and the last digit of q is not '0'.
Given the surviving digit string s, recover every pair of readings (L, R) that could have produced it: choose a split point 1 <= i < |s| dividing s into a left block s[0:i] and a right block s[i:], then choose a valid reading L derivable from the left block and a valid reading R derivable from the right block (each independently either a plain integer or a decimal-point insertion).
Because several splits and insertions can be valid at once, list every recoverable pair in one fixed order: for a given split point, list the left block's valid readings with the plain-integer form first (if valid), followed by the decimal forms in order of increasing length of the integer part; do the same for the right block. For that split point, form all (L, R) pairs by looping over left readings in the outer position and right readings in the inner position (in the orders just described). Finally, iterate split points i from 1 to |s|-1 in increasing order as the outermost loop, printing one line (L, R) for every pair found this way, in the exact order generated.
If no split point yields any valid pair, print a single line containing NONE instead.
A single line containing a string s of decimal digits, with 2 <= |s| <= 12.
Print the pair lines described above, one per line, in the exact canonical order specified; or print the single line NONE if there are none.
2 <= length of s <= 12. s consists only of the characters '0'-'9'.
Example 1
Input
0123
Expected
(0, 123) (0, 1.23) (0, 12.3) (0.1, 23) (0.1, 2.3) (0.12, 3)
Explanation
s="0123", splits i=1..3. i=1: left="0" (only valid reading: "0"), right="123" (readings "123", "1.23", "12.3") -> pairs (0,123),(0,1.23),(0,12.3). i=2: left="01" (plain invalid; only decimal "0.1" valid), right="23" (readings "23","2.3") -> pairs (0.1,23),(0.1,2.3). i=3: left="012" (plain invalid; decimal k=1 gives "0.12" valid, k=2 gives p="01" invalid), right="3" ("3") -> pair (0.12,3). Concatenating in split order gives the 6 lines shown.
Example 2
Input
000
Expected
NONE
Explanation
s="000", splits i=1,2. i=1: left="0" is valid ("0"), but right="00": plain invalid (leading zero, length>1), and its only decimal split (p="0", q="0") is invalid because q ends in '0' -- so right has no valid reading, giving zero pairs. i=2: left="00": plain invalid, and its only decimal split (p="0", q="0") is invalid for the same trailing-zero reason -- so left has no valid reading either, giving zero pairs. No split produced any pair, so the output is NONE.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →