NetEase Programming Title _ String Code __ Database

Source: Internet
Author: User

Given a string, you should encode the string to replace the consecutive characters with the number of consecutive occurrences + characters. For example, string AAAABCCDAA will be encoded into 4A1B2C1D2A.
Enter a description:

Each test entry contains 1 test cases
Each test case is entered with only one line of string, and the string contains only uppercase letters, not exceeding 10000 in length.

Output Description:

Output encoded string

Enter an example:

Aaaabccdaa

Output Example:

4a1b2c1d2a

#include <string>
#include <iostream>

int main ()
    {
    std::string input;
    std::cin>>input;
    Std::string::iterator First=input.begin (), Last=input.begin ();
    while (Last!=input.end ())
        {
        int cnt=0;
        while (Last!=input.end () && *first==*last)
            {
            ++cnt;
            ++last;
        }
        std::cout<<cnt<<*first;
        i = Last;
    }

    return 0;
}

http://blog.csdn.net/sinat_27935693/article/details/60140315

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.