spoj: runlength

Posted by user285825 on Stack Overflow See other posts from Stack Overflow or by user285825
Published on 2010-04-19T04:14:11Z Indexed on 2010/04/19 4:23 UTC
Read the original article Hit count: 529

Filed under:

For RLM problem of SPOJ:

This is the problem:

"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."

These are my testcases: input:

11 + 11

988726 - 978625

12 * 41

1124 / 1112

13 * 33

15 / 16

19222317121013161815142715181017 + 10

10 + 19222317121013161815142715181017

19222317121013161815142715181017 / 19222317121013161815142715181017

19222317121013161815142715181017 / 11

11 / 19222317121013161815142715181017

19222317121013161815142715181017 / 12

12 / 19222317121013161815142715181017

19222317121013161815142715181017 / 141621161816101118141217131817191014

141621161816101118141217131817191014 / 19222317121013161815142715181017

19222317121013161815142715181017 / 141621161816101118141217131817191013

141621161816101118141217131817191013 / 19222317121013161815142715181017

19222317121013161815142715181017 * 11

11 * 19222317121013161815142715181017

19222317121013161815142715181017 * 10

10 * 19222317121013161815142715181017

19222317121013161815142715181017 - 10

19222317121013161815142715181017 - 19222317121013161815142715181017

19222317121013161815142715181017 - 141621161816101118141217131817191014

19222317121013161815142715181017 - 141621161816101118141217131817191013

141621161816101118141217131817191013 + 141621161816101118141217131817191013

141621161816101118141217131817191013 + 141621161816101118141217131817191014

141621161816101118141217131817191014 + 141621161816101118141217131817191013

141621161816101118141217131817191014 + 10

10 + 141621161816101118141217131817191013

141621161816101118141217131817191013 + 11

11 + 141621161816101118141217131817191013

141621161816101118141217131817191013 * 12

12 * 141621161816101118141217131817191013

141621161816101118141217131817191014 - 141621161816101118141217131817191014

141621161816101118141217131817191013 - 141621161816101118141217131817191013

141621161816101118141217131817191013 - 10

141621161816101118141217131817191014 - 11

141621161816101118141217131817191014 - 141621161816101118141217131817191013

141621161816101118141217131817191014 / 141621161816101118141217131817191014

141621161816101118141217131817191014 / 141621161816101118141217131817191013

141621161816101118141217131817191013 / 141621161816101118141217131817191014

141621161816101118141217131817191013 / 141621161816101118141217131817191013

141621161816101118141217131817191014 * 11

11 * 141621161816101118141217131817191014

141621161816101118141217131817191014 / 11

11 / 141621161816101118141217131817191014

10 + 10

10 + 11

10 + 15

15 + 10

11 + 10

11 + 10

10 - 10

15 - 10

10 * 10

10 * 15

15 * 10

10 / 111213

output:

11 + 11 = 12

988726 - 978625 = 919111

12 * 41 = 42

1124 / 1112 = 1112

13 * 33 = 39

15 / 16 = 10

19222317121013161815142715181017 + 10 = 19222317121013161815142715181017

10 + 19222317121013161815142715181017 = 19222317121013161815142715181017

19222317121013161815142715181017 / 19222317121013161815142715181017 = 11

19222317121013161815142715181017 / 11 = 19222317121013161815142715181017

11 / 19222317121013161815142715181017 = 10

19222317121013161815142715181017 / 12 = 141621161816101118141217131817191013

12 / 19222317121013161815142715181017 = 10

19222317121013161815142715181017 / 141621161816101118141217131817191014 = 11

141621161816101118141217131817191014 / 19222317121013161815142715181017 = 10

19222317121013161815142715181017 / 141621161816101118141217131817191013 = 12

141621161816101118141217131817191013 / 19222317121013161815142715181017 = 10

19222317121013161815142715181017 * 11 = 19222317121013161815142715181017

11 * 19222317121013161815142715181017 = 19222317121013161815142715181017

19222317121013161815142715181017 * 10 = 10

10 * 19222317121013161815142715181017 = 10

19222317121013161815142715181017 - 10 = 19222317121013161815142715181017

19222317121013161815142715181017 - 19222317121013161815142715181017 = 10

19222317121013161815142715181017 - 141621161816101118141217131817191014 =

141621161816101118141217131817191013

19222317121013161815142715181017 - 141621161816101118141217131817191013 =

141621161816101118141217131817191014

141621161816101118141217131817191013 + 141621161816101118141217131817191013 =

19222317121013161815142715181016

141621161816101118141217131817191013 + 141621161816101118141217131817191014 =

19222317121013161815142715181017

141621161816101118141217131817191014 + 141621161816101118141217131817191013 =

19222317121013161815142715181017

141621161816101118141217131817191014 + 10 = 141621161816101118141217131817191014

10 + 141621161816101118141217131817191013 = 141621161816101118141217131817191013

141621161816101118141217131817191013 + 11 = 141621161816101118141217131817191014

11 + 141621161816101118141217131817191013 = 141621161816101118141217131817191014

141621161816101118141217131817191013 * 12 = 19222317121013161815142715181016

12 * 141621161816101118141217131817191013 = 19222317121013161815142715181016

141621161816101118141217131817191014 - 141621161816101118141217131817191014 = 10

141621161816101118141217131817191013 - 141621161816101118141217131817191013 = 10

141621161816101118141217131817191013 - 10 = 141621161816101118141217131817191013

141621161816101118141217131817191014 - 11 = 141621161816101118141217131817191013

141621161816101118141217131817191014 - 141621161816101118141217131817191013 = 11

141621161816101118141217131817191014 / 141621161816101118141217131817191014 = 11

141621161816101118141217131817191014 / 141621161816101118141217131817191013 = 11

141621161816101118141217131817191013 / 141621161816101118141217131817191014 = 10

141621161816101118141217131817191013 / 141621161816101118141217131817191013 = 11

141621161816101118141217131817191014 * 11 = 141621161816101118141217131817191014

11 * 141621161816101118141217131817191014 = 141621161816101118141217131817191014

141621161816101118141217131817191014 / 11 = 141621161816101118141217131817191014

11 / 141621161816101118141217131817191014 = 10

10 + 10 = 10

10 + 11 = 11

10 + 15 = 15

15 + 10 = 15

11 + 10 = 11

11 + 10 = 11

10 - 10 = 10

15 - 10 = 15

10 * 10 = 10

10 * 15 = 10

15 * 10 = 10

10 / 111213 = 10

I am getting consistently wrong answer. I generated the above testcases trying to make them as representative as possible (boundary conditions, etc). I am not sure how to test it further. Some guidline would be really appreciated.

© Stack Overflow or respective owner

Related posts about spoj