CF394A.Counting Sticks

普及/提高-

通过率:0%

时间限制:0.50s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

When new students come to the Specialized Educational and Scientific Centre (SESC) they need to start many things from the beginning. Sometimes the teachers say (not always unfairly) that we cannot even count. So our teachers decided to teach us arithmetics from the start. And what is the best way to teach students add and subtract? — That's right, using counting sticks! An here's our new task:

An expression of counting sticks is an expression of type:

[ A sticks][sign +][B sticks][sign =][C sticks] (1 ≤ A, B, C).

Sign + consists of two crossed sticks: one vertical and one horizontal. Sign = consists of two horizontal sticks. The expression is arithmetically correct if A + B = C.

We've got an expression that looks like A + B = C given by counting sticks. Our task is to shift at most one stick (or we can shift nothing) so that the expression became arithmetically correct. Note that we cannot remove the sticks from the expression, also we cannot shift the sticks from the signs + and =.

We really aren't fabulous at arithmetics. Can you help us?

当新生来到专门教育与科学中心(SESC)时,他们需要从头开始学习许多东西。有时老师们会说(并非总是不公平地):“我们甚至都不会算数!”因此,老师们决定从最基础的算术教起。而教授学生加法和减法的最佳方式是什么呢?——没错,就是用计数棒!于是,我们迎来了下面这个新任务:

一个“计数棒表达式”是指如下形式的表达式:

[ A \text{ 根棒} ][符号 +][B \text{ 根棒} ][符号 =][C \text{ 根棒} ](其中 1≤A, B, C1 \leq A,\, B,\, C)。

符号 + 由两根交叉的棒组成:一根竖直、一根水平;符号 = 由两根水平的棒组成。若满足 A+B=CA + B = C,则该表达式在算术意义上是正确的。

现给出一个由计数棒构成的形如 A+B=CA + B = C 的表达式。我们的任务是:最多移动一根棒(也可以不移动任何棒),使得该表达式在算术意义上变为正确。注意:我们不能从表达式中移除任何棒,也不能移动属于符号 + 或 = 的棒。

我们在算术方面真的不太在行。你能帮帮我们吗?

输入格式

The single line contains the initial expression. It is guaranteed that the expression looks like A + B = C, where 1 ≤ A, B, C ≤ 100.

单行包含初始表达式。保证该表达式形如 A + B = C,其中 1 ≤ A, B, C ≤ 100。

输出格式

If there isn't a way to shift the stick so the expression becomes correct, print on a single line "Impossible" (without the quotes). If there is a way, print the resulting expression. Follow the format of the output from the test samples. Don't print extra space characters.

If there are multiple correct answers, print any of them. For clarifications, you are recommended to see the test samples.

如果无法通过移动火柴棒使等式成立,则在一行中输出 "Impossible"(不带引号)。如果可以,请输出移动火柴棒后得到的等式。输出格式需与测试样例一致,不要输出额外的空格字符。

若存在多个正确答案,输出任意一个即可。如有疑问,建议参考测试样例。

输入输出样例

  • 输入#1

    ||+|=|||||

    输出#1

    |||+|=||||
  • 输入#2

    |||||+||=||

    输出#2

    Impossible
  • 输入#3

    |+|=||||||

    输出#3

    Impossible
  • 输入#4

    ||||+||=||||||

    输出#4

    ||||+||=||||||

说明/提示

In the first sample we can shift stick from the third group of sticks to the first one.

In the second sample we cannot shift vertical stick from + sign to the second group of sticks. So we cannot make a - sign.

There is no answer in the third sample because we cannot remove sticks from the expression.

In the forth sample the initial expression is already arithmetically correct and that is why we don't have to shift sticks.

在第一个样例中,我们可以将第三组火柴棒中的一根移动到第一组。

在第二个样例中,我们无法将“+”号中的竖直火柴棒移至第二组火柴棒,因此无法构成“−”号。

第三个样例中无解,因为我们不能从表达式中移除火柴棒。

在第四个样例中,初始表达式本身在算术上已正确,因此无需移动火柴棒。

输入解题思路,AI测评打分。不知道怎么写?

首页