5399.Noonerized Spumbers

Time Limit: 1s Memory Limit: 256MB

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:
KNA81F9Dqs5e7lQqn7xtOfGDl3sVxiq1ELRcZ53x.png
what he really intended to write was:

mFj9YCpjhiVjivLDL3t05KQ6VxmaQ6K6BVQlCO6x.png
(He swapped prefixes “9” and “669” in the first and third numbers.) And when he writes:

EIaJFj61zAUPqfWPDr4hQdxzH60EJwdGyOayiULX.png
what he really intended to write was:

zPrFmDhw4X8pV8ld5keEHnng1q8hK0uskY7S6CyI.png

(He swapped the prefix “72” with the prefix “68” in the first and second numbers.)

Grading homework from young Mr. Spooner is quite a challenge. Fleas pined a way to help!

Input Format(From the terminal/stdin)

The input consists of a single line containing an expression of the form $x + y = z$ or $x * y = z$, where $x$, $y$, and $z$ are positive integers less than $2^{31}$. There will be single spaces surrounding the $+$ and $*$ operators and the $=$ sign. The expression will not be a mathematically correct equation.

Output Format(To the terminal/stdout)

Output a mathematically correct equation consisting of the input line modified by swapping proper
prefixes of two of the three numbers $x$, $y$, $z$. (A proper prefix of a string $s$ is a prefix that is neither empty nor equal to $s$.) Separate the numbers, operators, and the $=$ sign with single spaces. All integers in the correct equation will be non-negative and less than $2^{31}$. There is guaranteed to be only one possible correct equation that can be formed by swapping proper prefixes.

Sample Input 1

Copy
92 + 2803 = 669495
  · ·    · ·      \n

Sample Output 1

Copy
6692 + 2803 = 9495
    · ·    · ·    \n

Sample Input 2

Copy
6891 * 723 = 4979753
    · ·   · ·       \n

Sample Output 2

Copy
7291 * 683 = 4979753
    · ·   · ·       \n
Source: ECNA 2021

Submit

请先 登录

© 2025 FAQs