Codeforces Round #231 (Div. 2)

 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.

题解:

加数棍子,只能移动一个,不可以移除出等式,使加法式子成立。


代码:

#include <stdio.h>
#include <string.h>

int main()
{
	char str[200000];
	int i,len, fir_num=0, sec_num=0, thr_num=0, tmp=0;
//	freopen("code.in", "r", stdin);
//	freopen("code.out", "w", stdout);
	memset(str, '\0', sizeof(str));
	scanf("%s", &str);
	len = strlen(str);
	for (i=0; i<len; i++)
	{
		if (str[i] == '+')
			fir_num = i;
		if (str[i] == '=')
			sec_num = i - fir_num - 1;
	}
	
	thr_num = len - (sec_num  + fir_num + 1)-1;
	// 满足正常的加法,输出
	if (fir_num + sec_num == thr_num)
	{
		printf("%s\n", str);
		return 0;
	}
	//加数比和小了2,和加一,加数减一
	else if (fir_num + sec_num == (thr_num-2))
	{
		thr_num = thr_num -1;
		fir_num = fir_num +1;
		for (i=0; i<fir_num; i++)
			printf("|");
		printf("+");
		for (i=0;i<sec_num; i++)
			printf("|");
		printf("=");
		for(i=0;i<thr_num; i++)
			printf("|");
		printf("\n");
		return 0;
	}
	// 加数比和大了2,和减一,加数加一 
	else if (thr_num == (sec_num + fir_num - 2))
	{
		if (fir_num >1 )
			fir_num = fir_num - 1;
		else
			sec_num = sec_num - 1;
		thr_num = thr_num + 1;
		for (i=0; i<fir_num; i++)
			printf("|");
		printf("+");
		for (i=0;i<sec_num; i++)
			printf("|");
		printf("=");
		for(i=0;i<thr_num; i++)
			printf("|");
		printf("\n");
		return 0;		
	}
	// 其他情况不可能
	else
	{
		printf("Impossible\n");
		return 0;
	}
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值