移动一根棍子-简单的拼图可以帮助 [英] Move one stick -simple puzzle can help

查看:158
本文介绍了移动一根棍子-简单的拼图可以帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个简单的难题:在下图中移动一根摇杆以使方程式正确.

http://livearchive.onlinejudge.org/external/40/p4092a.png [ ^ ]



容易吧?解决方法如下:


http://livearchive.onlinejudge.org/external/40/p4092b.png [ ^ ]


编写一个程序来解决类似的难题,要知道:

每个难题都由一个左操作数,一个运算符,一个右操作数,一个等号和一个结果组成.这两个操作数和结果均为数字,由一个或多个数字组成,且小于231.
运算符和等号不能更改.您只能移动组成数字的摇杆.
您既不能完全删除数字,也不能引入新数字. (即,您只能更改数字.)
输入和输出中都允许前导零.必须打印输出中的前导零.
每个难题都指定了所需动作的数量.您的解决方案必须移动指定数量的木棍.摇杆最多只能移动一次;无法再次移动.如果移动了摇杆,则其原始位置必须保持空白. (即,您不能将其他棍子移动到该位置.)
解决涉及除法的难题时,除法必须是精确的整数除法,即无余数.
数字被``写''如下:


http://livearchive.onlinejudge.org/external/40/p4092c.png [ ^ ]

输入

您的程序将在一个或多个测试用例上进行测试.每个测试用例都使用以下格式在一行上指定:

A B = R(n)

其中A,B和R是一个或多个数字的序列,但不超过9个数字.是四个运算符之一:`+-*/". n是一个自然数,表示要移动的摇杆数.一个或多个空格分隔A,B,=,R和(n).
测试用例的结尾由带有单词``EOF''的单独行指示(不带引号).

输出

对于每个难题,您的程序必须打印以下形式的一行:


.结果


其中k是难题编号(从1开始)是单个空格,结果是解决难题之后的方程.结果不包含空格.

如果有多种解决方案,则仅打印一种.如果无法解决难题,请打印"UNSOLVABLE"(不带引号)作为结果.

样本输入

6 +1 = 12(1)
81 * 8 = 1(3)
5-1 = 4(1)
EOF
样本输出

1. 5 + 7 = 12
2. 01 * 3 = 3
3. UNSOLVABLE

Here''s a simple puzzle: Move one stick in the figure below to make the equation correct.

http://livearchive.onlinejudge.org/external/40/p4092a.png[^]



Easy, right? Here''s the solution:


http://livearchive.onlinejudge.org/external/40/p4092b.png[^]


Write a program to solve similar puzzles knowing that:

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 231 .
The operator and the equal sign cannot be changed. You''re only allowed to move sticks making up the digits.
You can neither remove digits completely nor introduce new ones. (i.e. You can only alter the digits.)
Leading zeros are allowed in both the input and output. Leading zeros in the output must be printed.
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.)
When solving a puzzle involving division, the division must be an exact integer division, i.e. no remainder.
Digits are ``written" as follows:


http://livearchive.onlinejudge.org/external/40/p4092c.png[^]

Input

Your program will be tested on one or more test cases. Each test case is specified on a single line using the following format:

A B = R(n)

where A , B , and R are sequences of one or more digits, but no more than nine digits. is one of the four operators: `+ - * /''. n is a natural number representing the number of sticks to move. One or more spaces separate A , , B , =, R , and (n ).
The end of the test cases is indicated by a separate line having the word ``EOF" (without the quotes.)

Output

For each puzzle, your program must print one line of the form:


k . result


Where k is the puzzle number (starting at 1,) is a single space, and 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 ``UNSOLVABLE" (without the quotes) as the result .

Sample Input

6 + 1 = 12 (1)
81 * 8 = 1 (3)
5 - 1 = 4 (1)
EOF
Sample Output

1. 5+7=12
2. 01*3=3
3. UNSOLVABLE

推荐答案

我们告诉过您,这里的工作方式并非如此.这是您的作业,应该继续进行.

这是询问者的期望:
1. 先尝试您要做什么!您可能会发现它并不难.
2.制定看起来像问题/无法解决的问题.

试试看,告诉他们是否遇到问题.
成员将很乐意为您提供帮助.



尝试从这里开始,执行以下步骤:
1.将A,B和R定义为一个或多个数字的序列,但不超过9个数字.
2.定义一个可以是四个运算符之一的"X":`+-*/".
3.将"n"定义为代表要移动的摇杆数量的自然数.
4.要求输入基于1、2&的信息. 3.
5.重复4,直到看到"EOF"(不带引号).

继续.
We told you that it does not work like this here. This is your assignment and you should work on it.

Here is what is expected of enquirers:
1. TRY first what you want to do! You may find that it''s not that hard.
2. Formulate what was done by you that looks like an issue/not working.

Try them and tell if you face issues.
Members will be more than happy to help like this.



Try, start from here, steps:
1. Define A , B , and R as sequences of one or more digits, but no more than nine digits.
2. Define an ''X'' that can be one of the four operators: `+ - * /''.
3. Define ''n'' as a natural number representing the number of sticks to move.
4. Ask for input based on 1, 2 & 3.
5. Repeat 4 until you see "EOF" (without the quotes.)

Move on.


这篇关于移动一根棍子-简单的拼图可以帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆