eolymp
bolt
Try our new interface for solving problems
Problems

Moving Sticks

Moving Sticks

Here’s a simple puzzle: Move one stick in the figure below to make the equation correct. \includegraphics{https://static.e-olymp.com/content/8c/8c359cf9fd4d45aee27dc5c1bc17fd3a9040140e.jpg} Easy, right? Here’s the solution: \includegraphics{https://static.e-olymp.com/content/16/162713af869108baf07c376f0f61e43e4f9d50c6.jpg} Write a program to solve similar puzzles knowing that: \begin{enumerate} \item Each puzzle is made of a left operand, an operator, a right operand, an equal sign, and a result. The two operands and the result are numbers, made of one or more digits, and is less than \textbf{2^31}. \item The operator and the equal sign cannot be changed. You’re only allowed to move sticks making up the digits. \item You can neither remove digits completely nor introduce new ones. (i.e. You can only \textit{alter the digits}.) \item Leading zeros are allowed in both the input and output. Leading zeros in the output must be printed. \item Each puzzle specifies the number of required moves. Your solution must move as many sticks as specified. A stick is moved at most once; It cannot be moved again. If a stick is moved, its original place must remain vacant. (i.e. you cannot move another stick to that place.) \item When solving a puzzle involving division, the division must be an \textit{exact integer division}, i.e. no remainder. \item Digits are "written" as follows: \end{enumerate} \includegraphics{https://static.e-olymp.com/content/e5/e54836b41ce5a3aa74def65d5c716853c5fb6a3d.jpg} \InputFile Your program will be tested on one or more test cases. Each test case is specified on a single line using the following format: \textbf{A ⊙ B = R (n)} where \textbf{A}, \textbf{B}, and \textbf{R} are sequences of one or more digits, but no more than nine digits. \textbf{⊙} is one of the four operators: \textbf{+ - * /}. \textbf{n} is a natural number representing the number of sticks to move. One or more spaces separate \textbf{A}, \textbf{⊙}, \textbf{B}, \textbf{=}, \textbf{R}, and (\textbf{n}). The end of the test cases is indicated by a separate line having the word "\textbf{EOF}" (without the quotes). \OutputFile For each puzzle, your program must print one line of the form: \textbf{k. result} Where \textbf{k} is the puzzle number (starting at \textbf{1}), and \textbf{result} is the equation after solving the puzzle. result includes no spaces. In the case of multiple solutions, print just one. If the puzzle can’t be solved, print "\textbf{UNSOLVABLE}" (without the quotes) as the result.
Time limit 1 second
Memory limit 64 MiB
Input example #1
6 + 1 = 12 (1)
81 * 8 = 1 (3)
5 - 1 = 4 (1)
EOF
Output example #1
1. 5+7=12
2. 01*3=3
3. UNSOLVABLE