## p309ex13: Calculator

Given two integers A and B (0 ≤ A, B < 2^32 - base 10), in bases B1 and B2 (2 ≤ B1, B2 ≤ 10), output the result of either `+ - * /` in the integral base BF (2 ≤ BF ≤ 10). The resulting answer will be less than 2^32 in base 10, and will always be positive.

Perform integer division (5 / 2 = 2) on the operands. Substitute the operand into (A <operand here> B) - so you should perform (A - B), (A / B), etc.

### Input

Line 1: One integer T (1 ≤ T ≤ 100) denoting the number of test cases.
T test cases follow, and each test case consists of 6 lines, with test cases separated by newlines.

Each test case has the following format:
Line 1: B1
Line 2: N1
Line 3: B2
Line 4: N2
Line 5: The operand (Either '+', '-', '*', or '/')
Line 6: BF

```2
10
123
10
456
+
10

8
777
5
333
-
2

```

### Sample Output

```579
110100010```

Point Value: 5
Time Limit: 2.00s
Memory Limit: 16M
Added: Nov 01, 2008

Languages Allowed:
C++03, PAS, C, HASK, ASM, RUBY, PYTH2, JAVA, PHP, SCM, CAML, PERL, C#, C++11, PYTH3

## Comments (Search)

• (0/0)
why do i get re and mismatch, code works well on my complier, can someone help me?, so what is the problem exactly? im using long and chars in the correct places

• (0/0)

• (0/0)
this is hard, just to clarify, is Integer.toString disqualified?

• (2/2)
What does the program mean?
are you doing 2+123+10+456+10 in test case one. What does the program do? thank you

• (0/0)
 Given two integers A and B (0 ≤ A, B < 2^32 - base 10), in bases B1 and B2 (2 ≤ B1, B2 ≤ 10), output the result of either + - * / in the integral base BF (2 ≤ BF ≤ 10).

The first case asks you to add 123 to 456.
The second case asks you to subtract 333 (in base 5) from 777 (in base 8) and to express the result in base 2.

• (0/0)
This definitely needs to be worth more.
It's equal to Bases Multiplication (10pts), only you need to do more than just multiplication.

• (0/0)
Bases Multiplication should be worth less. Exercise problems like this are usually no more than 5 points; 10 points are generally given for the easiest problems that actually require some thinking (e.g., Plentiful Paths). I changed Bases Multiplication to 5 and this one also to 5.