File size: 1,013 Bytes
c4b0eef
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
 * Written by Nitin Kumar Maharana
 * nitin.maharana@gmail.com
 */

#include <iostream>
#include <string>

using namespace std;

bool isNumber(char *str)
{
	bool flag = true;

	for(int i = 0; str[i] != '\0'; i++)
	{
		if(str[i] < '0' || str[i] > '9')
		{
			flag = false;
			break;
		}
	}

	return flag;
}

int toNumber(char *str)
{
	int number;

	number = 0;

	for(int i = 0; str[i] != '\0'; i++)
		number = (number * 10) + (str[i] - '0');

	return number;
}

int main(void)
{
	int t;
	char number1[30], number2[30], sum[30];
	int n1, n2, summ;
	char plus, equal;

	cin >> t;

	while(t--)
	{
		cin >> number1 >> plus >> number2 >> equal >> sum;

		n1 = n2 = summ = -1;

		if(isNumber(number1))
			n1 = toNumber(number1);

		if(isNumber(number2))
			n2 = toNumber(number2);

		if(isNumber(sum))
			summ = toNumber(sum);

		n1 = (n1 == -1) ? (summ - n2) : n1;
		n2 = (n2 == -1) ? (summ - n1) : n2;
		summ = (summ == -1) ? (n1 + n2) : summ;

		cout << n1 << " + " << n2 << " = " << summ << endl;
	}

	return 0;
}