Noonerized Spumbers
Time limit1sMemory limit1024 MB
Given a false arithmetic equation x op y = z, swap proper prefixes of two of the three numbers to make the equation true.
- Level
Medium5 of 10
- Topics
- Brute force, String, Implementation, Math
- Solved
- No attempts yet
Problem
Everyone has heard of spoonerisms, named after William Archibald Spooner, an Oxford professor who had a habit of swapping prefixes of words, often with comical results. "May I show you to your seat?" became "May I sew you to your sheet?" and "a crushing blow" became "a blushing crow."
Just imagine him as a student of arithmetic, occasionally swapping the prefixes of the numbers he was calculating with and then wondering why his equations never made any sense. For instance, when he writes:

what he really intended to write was:

(He swapped prefixes "" and "" in the first and third numbers.) And when he writes:

what he really intended to write was:

(He swapped the prefix "" with the prefix "" in the first and second numbers.)
Grading homework from young Mr. Spooner is quite a challenge. Fleas pined a way to help!
Input
The input consists of a single line containing an expression of the form "" or "", where , , and are positive integers less than . There will be single spaces surrounding the "" and "" operators and the "" sign. The expression will not be a mathematically correct equation.
Output
Output a mathematically correct equation consisting of the input line modified by swapping proper prefixes of two of the three numbers , , . (A proper prefix of a string is a prefix that is neither empty nor equal to .) Separate the numbers, operators, and the "" sign with single spaces. All integers in the correct equation will be non-negative and less than . There is guaranteed to be only one possible correct equation that can be formed by swapping proper prefixes.