RLM - Run-Length Mathematics

no tags 

Run-length encoding of a number replaces a run of digits (that is, a sequence of consecutive equivalent digits) with the number of digits followed by the digit itself. For example, 44455 would become 3425 (three fours, two fives). Note that run-length encoding does not necessarily shorten the length of the data: 11 becomes 21, and 42 becomes 1412. If a number has more than nine consecutive digits of the same type, the encoding is done greedily: each run grabs as many digits as it can, so 111111111111111 is encoded as 9161.

Implement an integer arithmetic calculator that takes operands and gives results in run-length format. You should support addition, subtraction, multiplication, and division. You won't have to divide by zero or deal with negative numbers.

Input/Output

The input will consist of several test cases, one per line. For each test case, compute the run-length mathematics expression and output the original expression and the result, as shown in the examples. The (decimal) representation of all operands and results will fit in signed 64-bit integers.

Example

Input:
11 + 11
988726 - 978625
12 * 41
1124 / 1112
13 * 33
15 / 16

Output:
11 + 11 = 12
988726 - 978625 = 919111
12 * 41 = 42
1124 / 1112 = 1112
13 * 33 = 39
15 / 16 = 10

hide comments
smso: 2022-03-21 07:50:00

WA even with uint64_t in c++ but got accepted in python, input might overflow in c++.

spk20: 2020-07-20 21:28:13

how to exit??

jakobmierschei: 2020-07-19 19:58:06

Is there any special trick? I get a TLE with a relatively straight-forward solution. When should the program terminate after all?

Last edit: 2020-07-20 09:08:25
vengatesh15: 2017-09-07 13:20:44

easy one ..

hodobox: 2015-09-24 23:35:33

used long long -> WA
used unsigned long long -> AC

Himanshu: 2013-06-17 06:05:59

a tricky case::
i/p:
9292 - 92
o/p:
9292 - 92 = 9290
this cost me 2 WA.:)

Last edit: 2013-06-17 07:24:28
(^@_^@): 2012-06-22 06:36:21

learned some disastrous things about string data type
for input till endoffile use while (scanf("%s %[+-*/] %s",s1,ch,s2) !=EOF)
dont use while(!cin.eof()) with s1 s2 as string data type take as character array cause me many wa

Miorel-Lucian Palii: 2009-11-26 07:17:47

Generally I would agree. Unfortunately many contests do not provide such information. This problem is meant to prepare you for such contests ;)

And for this particular problem, the time limit doesn't seem to be an issue, as I write this there are nearly 300 submissions and only 4 TLEs.

Seshadri R: 2009-11-04 16:46:02

Instead of saying several test cases, it would be helpful if an approximate number is specified. This will enable us to prepare test data of the stated magnitude and test whether our submission would suffer TLE or not


Added by:Miorel Palii
Date:2009-10-04
Time limit:1s
Source limit:4096B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ERL NODEJS PERL6 VB.NET
Resource:University of Florida Local Contest - April 13, 2009