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