String Encoding C #

Source: Internet
Author: User

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 #

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.