Given a string, you re-encode the string and replace the successive characters with the "number of consecutive occurrences + characters". For example, string AAAABCCDAA will be encoded into 4A1B2C1D2A.
Input Description:
Each test input contains 1 test cases each test case input has only one line of string, the string contains only uppercase English letters, the length does not exceed 10000.
Output Description:
Output encoded string
Input Example:
Aaaabccdaa
Output Example:
4a1b2c1d2a
The New Ket Web page runs the following code:
usingSystem; Public classprogram{ Public Static voidMain () {stringinput =System.Console.ReadLine (); intInputlength =input. Length; intKeycount =0; CharKeyValue; Char[] C =New Char[Inputlength]; for(inti =0; i < inputlength; i++) {C[i]= Convert.tochar (input. Substring (I,1)); } for(inti =0; I <inputlength;) {KeyValue=C[i]; while(I! = inputlength && KeyValue = =C[i]) {i++; Keycount++; } console.write ("{0}{1}", Keycount, KeyValue); Keycount=0; } console.readkey (); }}
The code in VS is as follows:
usingSystem;namespacestring Encoding {classProgram {Static voidMain (string[] args) { stringinput =System.Console.ReadLine (); intInputlength =input. Length; intKeycount =0; CharKeyValue; Char[] C =New Char[Inputlength]; for(inti =0; i < inputlength; i++) {C[i]= Convert.tochar (input. Substring (I,1)); } for(inti =0; I <inputlength;) {KeyValue=C[i]; while(I! = inputlength && KeyValue = =C[i]) {i++; Keycount++; } console.write ("{0}{1}", Keycount, KeyValue); Keycount=0; } console.readkey (); } }}
Welcome to the Exchange.
String Encoding C #