Find the longest consecutive number string

Source: Internet
Author: User
Tags numeric
Write a function whose prototype is the int continuemax (CHAR*OUTPUTSTR,CHAR*INPUTSTR) function: Find the longest consecutive number string in the string and return the length of this string, and send this longest number string to one of the function parameters outputstr the memory. For example: After the first address of "ABCD12345E123456789D125SS" is passed to Intputstr, the function returns a value of 123456789 that is referred to by 9,OUTPUTSTR.
 #include <iostream> using namespace std;
	int Continuemax (char* outputstr,char* inputstr) {int max=0;//string with longest consecutive length int cnt;//record number of consecutive numeric characters char* tmp0=null;
	char* Tmp1=null;
	int i;
	for (;;)	 
		{while (*inputstr! = 0 && (*inputstr > ' 9 ' | | *inputstr < ' 0 '))//skip non-numeric characters ++inputstr; CNT = 0;
		Must clear 0 tmp0=inputstr;
			while (*inputstr! = 0 && (*inputstr >= ' 0 ' && *inputstr <= ' 9 '))//detect numeric characters {++cnt;	
		++INPUTSTR; 
			} if (cnt > Max) {max=cnt;  Tmp1=tmp0;	
	Tmp1 points to the longest first address of consecutive numeric characters} if (*inputstr = = 0)//The string ends after jumping out of the loop break;
	} for (I=0;i<max;++i)//To copy the longest consecutive number string into Outputstr * (outputstr+i) =* (tmp1+i);	* (outputstr+i) = ' + ';	
String ending character return max; 
	} int main () {char* inputstr= "abcd12345ed125ss123456789";
	Char outputstr[100]; 
	int Max; 
	Max=continuemax (OUTPUTSTR,INPUTSTR);  
	cout<<max<< "" <<outputstr<<endl; 
	System ("pause");   
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.