## CCC '19 J3 - Cold Compress

View as PDF

Points: 5
Time limit: 1.0s
Memory limit: 256M

Problem type
##### Canadian Computing Competition: 2019 Stage 1, Junior #3

Your new cellphone plan charges you for every character you send from your phone. Since you tend to send sequences of symbols in your messages, you have come up with the following compression technique: for each symbol, write down the number of times it appears consecutively, followed by the symbol itself. This compression technique is called run-length encoding.

More formally, a block is a substring of identical symbols that is as long as possible. A block will be represented in compressed form as the length of the block followed by the symbol in that block. The encoding of a string is the representation of each block in the string in the order in which they appear in the string.

Given a sequence of characters, write a program to encode them in this format.

#### Input Specification

The first line of input will contain the number , which is the number of lines that follow. The next lines will contain at least one and at most characters, none of which are spaces.

#### Output Specification

Output will be lines. Line of the output will be the encoding of the line of the input. The encoding of a line will be a sequence of pairs, separated by a space, where each pair is an integer (representing the number of times the character appears consecutively) followed by a space, followed by the character.

#### Sample Input

4
+++===!!!!
777777......TTTTTTTTTTTT
(AABBC)
3.1415555

#### Output for Sample Input

3 + 3 = 4 !
6 7 6 . 12 T
1 ( 2 A 2 B 1 C 1 )
1 3 1 . 1 1 1 4 1 1 4 5

#### Explanation of Output for Sample Input

To see how the first message (on the second line of input) is encoded, notice that there are + symbols, followed by = symbols, followed by ! symbols.

• commented on Sept. 21, 2022, 12:09 a.m.

This comment is hidden due to too much negative feedback. Show it anyway.

• commented on Sept. 22, 2022, 11:45 p.m. edited

To see how the first message (on the second line of input) is encoded, notice that there are 3 + symbols, followed by 3 = symbols, followed by 4 ! symbols.

• commented on Sept. 4, 2022, 2:36 p.m.

This comment is hidden due to too much negative feedback. Show it anyway.

• commented on Aug. 16, 2022, 10:22 p.m.

1w1h1a1t 1a1n 1o2p1o1s1i1t1e 1o1f(what an opposite of):

https://dmoj.ca/problem/ccc19j2

• commented on July 23, 2021, 2:58 p.m.

Me after seeing the title: ah this must have something to do with medical stuff! me after reading the question: what does this have to do with anything?

• commented on May 7, 2022, 9:06 p.m.

3 + 3 = 4 !

• commented on Oct. 23, 2021, 5:22 p.m.

relatable

• commented on Feb. 15, 2021, 9:23 p.m.

Can someone explain why I got AC on DMOJ but not on the CCC grader? Thanks!

• commented on April 26, 2021, 3:41 p.m.

first congrats to all ac on dmoj, and your question is caused by: there are probably different samples, ccc grader has more accurate samples but dmoj's sample maybe a little bit easier and not like that complicated, just my guess, hope this helps

• commented on July 27, 2020, 9:27 p.m.

Wow, so we have to pay every time we type. Why did we even get this plan.

• commented on Oct. 25, 2021, 11:59 p.m.

Cheapest plan out there?

• commented on Dec. 8, 2019, 7:18 p.m. edited

how do you check someone else submissions?

• commented on Dec. 8, 2019, 9:12 p.m.

You can only check other's submissions if you have solved the problem yourself, and once you do a view button will appear on anyone else's submission so you can see it.

• commented on July 29, 2020, 5:28 p.m.

Oh, thanks.

• commented on Oct. 13, 2019, 10:11 a.m. edited

3+3=4

h m m

• commented on Jan. 16, 2021, 2:31 a.m.

It would be correct if there're only 3 '!' XD

• commented on April 28, 2020, 4:45 p.m.

I knew someone was gonna say that XD