Run Length Encoding
Time Limit: 1000MS   Memory Limit: 30000K
Total Submissions: 3907   Accepted: 1282


Your task is to write a program that performs a simple form of run-length encoding, as described by the rules below. 
Any sequence of between 2 to 9 identical characters is encoded by two characters. The first character is the length of the sequence, represented by one of the characters 2 through 9. The second character is the value of the repeated character. A sequence of more than 9 identical characters is dealt with by first encoding 9 characters, then the remaining ones. 
Any sequence of characters that does not contain consecutive repetitions of any characters is represented by a 1 character followed by the sequence of characters, terminated with another 1. If a 1 appears as part of the sequence, it is escaped with a 1, thus two 1 characters are output. 


The input consists of letters (both upper- and lower-case), digits, spaces, and punctuation. Every line is terminated with a newline character and no other characters appear in the input.


Each line in the input is encoded separately as described above. The newline at the end of each line is not encoded, but is passed directly to the output.

Sample Input


Sample Output

int main()
char str[200];
int i,j,cnt,l;
if (!str[0])
if (str[i] == str[i+1])
for ( j = i ; str[i] == str[i+1] && (i-j) < 8 ; i++ );
printf("%d%c", i-j+1, str[i]);
} printf("\n");
memset(str, 0, sizeof(str));
return 0;

poj-1782 Run Length Encoding More articles about

  1. SDUT 2352 Run Length Encoding

    Let me see the title The question : Encode the given string , The coding rules are based on two ,1. If there are consecutive equal characters in a string , It becomes two characters , One is the number of the same characters in succession , The other is this character , But if the number exceeds 9 individual , Then output 9 Then the output ...

  2. Two-Pointer And Run Length Coding (RLC)

    Run length encoding (Run Length Coding, RLC) It is a common preprocessing method in string processing . It is written in a typical double pointer (Two-Pointer). The following is a summary of its writing 1. Input as a string of integers, you can not store integers in the array

  3. Count and Say (Array Length Encoding) -- LeetCode

    The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...

  4. POJ 1579-Function Run Fun( Memory search )

    Function Run Fun Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 16503   Accepted: 8514 ...

  5. Run length encoding (Run Length Code)

    One . What is run length coding Run length coding is a relatively simple compression algorithm , The basic idea is to use repeated and continuous characters ( The number of consecutive occurrences , A certain character ) To describe . Like a string : AAAAABBBBCCC Run length coding can be used to describe ...

  6. POJ.1379.Run Away( Simulated annealing )

    Topic link POJ The output can't be used %lf! mmp from 4:30 Change to 6:00, hold 4:30 The output has been changed . So there are two pieces of code .. //392K 500MS // Update with a rectangle of two points , You don't have to worry about boundaries #inc ...

  7. poj 1379 Run Away Simulated annealing difficulty :1

    Run Away Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 6482   Accepted: 1993 Descript ...

  8. POJ 1379 Run Away

    The question : Yes n Trap , stay X,Y A point in the range is required to make the minimum distance from the point to the trap maximum . Ideas : Simulated annealing , Randomly sprinkle 40 A little bit , Then simulated annealing randomizes the movement . ( This question poj Cheating father , added srand(time(NULL)) Can't pay ...

  9. POJ 1379 Run Away 【 Basic simulated annealing 】

    The question : Find out a little , The shortest distance from all points is the largest Two dimensional in-plane simulated annealing is enough , It is also possible to cover the problem with the smallest circle . Source Code: //#pragma comment(linker, "/ST ...

Random recommendation

  1. 【 tencent bugly Dry cargo sharing 】HTML 5 Live video one stop literacy

    This article is from Tencent bugly Developer community , Without the consent of the author , Do not reprint , Original address : Video straight ...

  2. swift Learning notes -UI Chapter UIImageView

    1. Basic use Drag the image you want to use into the project , I'm using the name “1.jpg” Pictures of the , Then create UIImageView, And set the image to be displayed as "1.jpg"//1. Basic use let im ...

  3. Milking Time

    Description Bessie is such a hard-working cow. In fact, she is so focused on maximizing her producti ...

  4. nignx note 1

    Here's a single version of the architecture , There is one theory tomcat Concurrent on 200 To 300, The most optimized 500, It's obviously low capacity , Moreover, after a single point of failure, the application service can not be accessed , such as tomcat, This is obviously not good for multi concurrency . So if I ...

  5. 【 Problem solving 】jhipster-registry-master Blank pages

    Summary of problems : Just from github Pulled down jhipster-registry-master Direct operation , visit http://localhost:8761 You'll find a blank page , But the website's title According to the normal , The purpose of this paper is to solve ...

  6. JavaScript Advanced ( One ) Pull out the common function

    JS Pull out the common function problem After going through " A lot of " After the development of the project , More and more methods can be pulled out and used as a public method . that , stay js How to realize this idea in the process of development ? answer for example , The following methods are used to implement the standard ...

  7. Javascript Review of advanced programming —— Chapter five types of citation 【 original 】

    5.1  Object type 1: establish Object Two ways of instance ①new Construction var obj1 = new Object(); Pay attention to capitalization ! You can omit parentheses when you don't pass parameters obj1.hehe = &quo ...

  8. ELK 5.6.8 Installation and deployment

    Operating system version : LSB Version: :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64: ...

  9. Node.js Version management tools nvm

    1. Download and install curl curl -o- | bash wge ...

  10. dnn ubuntu problem ...