Codeforces Round #231 (Div.2) - A. Counting Sticks

A. Counting Sticks

 

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?

Input

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

Output

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.

Sample test(s)
Input
||+|=|||||
Output
|||+|=||||
Input
|||||+||=||
Output
Impossible
Input
|+|=||||||
Output
Impossible
Input
||||+||=||||||
Output
||||+||=||||||
Note

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.

           
CF也就是AA水题吧。
#include <stdio.h>

int main()
{
    char s[10000];
    int a = 0,b = 0,c = 0;
    char *p;
    scanf ("%s",s);
    p = s;

    while (*p != '+')
    {
        if (*p == '|')
        a++;
        p++;
    }
    p++;
    while (*p != '=')
    {
        if (*p == '|')
        b++;
        p++;
    }
    p++;
    while (*p != '\0')
    {
        if (*p == '|')
        c++;
        p++;
    }
    if (a + b == c)
    {
        puts (s);
        return 0;
    }else
    {
        if (a + b + 2 == c)
        {
            a += 1;
            while(a--)
            {
                putchar ('|');
            }
            putchar ('+');
            while(b--)
            {
                putchar ('|');
            }
            putchar ('=');
            c -= 1;
            while(c--)
            {
                putchar ('|');
            }

            putchar ('\n');
            return 0;
        }else if (a + b == c + 2)
        {
            if (a > 1)
            {
                a -= 1;
            }else
            {
                b -= 1;
            }
            
            c += 1;
            
            while(a--)
            {
                putchar ('|');
            }
            putchar ('+');
            while(b--)
            {
                putchar ('|');
            }
            putchar ('=');
            while(c--)
            {
                putchar ('|');
            }

            putchar ('\n');
            return 0;
        }
    }
    puts ("Impossible");
    return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值