BSMATH1 - Math with Bases (Easy)
Little Ben had just learned different bases in math. He learned very quickly how to add and subtract in multiple bases, so his teacher provided him with a worksheet to work on. Each section provided a different base and gave an example.
Unfortunately, Little Ben's teacher forgot to write what base each question was in! Please help Little Ben do his homework; he'll be very grateful!
Input
The first line of input contains an integer n
(1 ≤ n < 36) that indicates the amount of sections (test cases). Each test case is as follows:
A - B = C
I
X1 op Y1 =
X2 op Y2 =
...
XI op YI =
where A - B = C
is the correct example, I
(1 ≤ I ≤ 1000) is the number of questions in that section, Xi
and Yi
are the operands of each problem (Xi
= |Xi
|, Yi
= |Yi
|), and op
is either + or -, denoting addition or subtraction.
Output
Your program should output in the following format:
SECTION 1 (BASE b)
X1 op Y1 = Z1
X2 op Y2 = Z2
...
Xi op Yi = Zi
SECTION 2 (BASE b)
X1 op Y1 = Z1
X2 op Y2 = Z2
...
Xi op Yi = Zi
...
SECTION N (BASE b)
X1 op Y1 = Z1
X2 op Y2 = Z2
...
Xi op Yi = Zi
where Zi
is the solution to Xi op Yi
, and b
is the base used. (2 ≤ b ≤ 36). If the base is ambiguous, use the smallest base for which the example is correct and the questions are valid. You may assume all solutions fit inside a 64-bit integer and that each base will appear at most once.
Example
Input:
4
110 - 101 = 1
2
1111111 + 1 =
100 - 1 =
177 + 1 = 200
2
7712347 + 7 =
11111 + 7777 =
ZAP + DZ = ZOO
1
E + PI =
10 + 1 = 11
1
5 + 5 =
Output:
SECTION 1 (BASE 2)
1111111 + 1 = 10000000
100 - 1 = 11
SECTION 2 (BASE 8)
7712347 + 7 = 7712356
11111 + 7777 = 21110
SECTION 3 (BASE 36)
E + PI = PW
SECTION 4 (BASE 6)
5 + 5 = 14
Notes:
- large input/output data, be careful with certain languages
- Tricky input/output; please read problem statement carefully
hide comments
vzemeow:
2023-11-22 16:12:39
мать ебал автора задавчи
|
|
katsuki:
2022-05-20 07:23:14
|
|
David:
2021-01-12 22:12:43
Why is the Java language excluded? Last edit: 2021-01-12 22:18:57 |
|
nadstratosfer:
2017-12-16 04:52:53
Unnecessarily tight time limit for this type of problem, almost lost a compact, elegant Python solution to a dreaded TLE. Looking back though, the tweaked bit that converted TLE to best Python runtime was an important lesson. Thanks Simes for pissing me off by ACing it while I whined ;) Last edit: 2017-12-16 21:03:00 |
|
Vamsi Krishna Avula:
2015-02-02 11:57:55
I thought the TL was strict but its quite opposite ;) |
Added by: | Jargon |
Date: | 2009-12-04 |
Time limit: | 0.100s-1s |
Source limit: | 5000B |
Memory limit: | 1536MB |
Cluster: | Cube (Intel G860) |
Languages: | ASM32 ASM64 BASH BF C C++ 4.3.2 CPP CPP14 C99 CLPS LISP sbcl D FORTRAN ICK NEM OCAML PAS-GPC PAS-FPC PRLG-swi PYTHON RUBY SCALA SCM guile SCM qobi ST TCL TEXT WHITESPACE |
Resource: | Own problem |