Find the longest consecutive numeric string in the string, find the longest consecutive numeric string in the string, and return the length of the string

Source: Internet
Author: User

Write a function. The original form is int continumax (char * outputstr, char * intputstr)
Function:
Find the longest consecutive numeric string in the string and return the length of the string,
And pay the longest numeric string to the memory specified by one of the function parameters outputstr.
For example, after the first address of "abcd12345ed125ss123456789" is passed to intputstr, the function returns 9,

# Include <iostream> using namespace STD; int continuemax (char * output, const char * input) {If (input = NULL) return 0; const char * hegin = NULL; int max_len = 0; while (* input) {If (! Isdigit (* input) {input ++; continue;} const char * temp = input; int sum = 0; For (; isdigit (* input); input ++, sum ++); If (sum> max_len) {max_len = sum; hegin = temp ;}} memcpy (output, hegin, max_len); Output [max_len] = 0; return max_len;} int main () {char output [100]; char input [100]; while (true) {CIN> input; // After the input is complete, \ 0 memset (output, 0, sizeof (output) is automatically added at the end; int Len = continuemax (output, input ); cout <Len <"" <output <Endl;} return 0 ;}

Find the longest consecutive numeric string in the string, find the longest consecutive numeric string in the string, and return the length of the string

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.