Convert the numeric string format to the character that appears in the original string + the number of consecutive occurrences of the character in the string p231

Source: Internet
Author: User
# Include <iostream> # include <string> using namespace STD; // convert the numeric string format to the character that appears in the original string + the number of consecutive occurrences of the character p231string func (string Str) {// string strchar; // string strnum; string ret; int Len = Str. length (); For (INT I = 0; I <Len; I ++) {// when it is a continuous character, skip and add an int COUNT = 1; while (STR [I] = STR [I + 1]) {count ++; I ++ ;} // count consecutive characters and the number of occurrences to the result string // strchar + = STR [I]; RET + = STR [I]; char TMP [10]; sprintf_s (TMP, "% d", count); // replace ITOA with // strnum + = TMP; RET + = TMP;} return ret;} int main () {/* char * P = "Hello World"; cout <strlen (p) <Endl; string STR; STR + = 'a'; STR + = 'B '; cout <STR <Endl; cout <Str. length () <Endl; */string STR ("111111111111223333"); cout <func (STR) <Endl; return 0 ;}

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.