Title Description
Please find the longest consecutive number string in the string, and return the length of the string, and if there is a continuous number string with the same length, the last consecutive number string is returned;
Note: The number string only needs to be composed of numbers, does not require order, such as the number string "1234" length is less than the number string "1359055", if there is no number, then return an empty string ("") instead of null!
Sample input
abcd12345ed125ss123058789
abcd12345ss54761
Sample output
Output 123058789, function return value 9
Output 54761, function return value 5
Interface description
Function Prototypes:
    continumax (char ** poutputstr, char * intputstr)
Input parameters:
Char* intputstr input string;
Output Parameters:
Char* * Poutputstr: The longest consecutive number of strings, ifcontinuous longest number of stringsa length of 0 should return an empty string, or an empty string if the input string is empty;
return value:
the length of the longest consecutive number string
The point of attention is a pointer to the pointer, the previous code:
#include <iostream>//#include <string>//#include <algorithm>//#include <cmath>//#include <vector>//#include <stack>//#include <iomanip>using namespace std; /* Function: Finds the longest consecutive number string in the string and returns the length of the string back to the function prototype: unsigned int continumax (char** poutputstr, char* intputstr) input parameters: char* intputst R input String output parameter: char** POUTPUTSTR: The longest consecutive number string, if the length of the longest consecutive number string is 0, should return an empty string poutputstr points to the memory should be within the function with the malloc function request, the call is responsible for releasing the return value: Long number string length */unsigned int Continumax (char** poutputstr, char* intputstr) {if (Poutputstr==null | | intputstr==null) return 0; int I,k,counti,maxcount,starti,maxstart;int Slen=strlen (INTPUTSTR); *poutputstr= (char *) malloc (slen+1);//cout< <slen<<endl;k=0;maxcount=0;while (K<slen) {for (i=k;i<slen;i++) {if (intputstr[i]>= ' 0 ' && intputstr[i]<= ' 9 ') {Starti=i;break;}} if (I==slen) break;counti=0;for (i=starti;i<slen;i++) if (intputstr[i]>= ' 0 ' && intputstr[i]<= ' 9 ') { counti++;} Else{if (maxcount<=counti) {maxcount=counti;maxstart=Starti;} break;} if (I==slen && maxcount<=counti) {maxcount=counti;maxstart=starti;break;} K=i;} cout<<maxcount<< "" <<maxstart<<endl;if (maxcount==0) {(*POUTPUTSTR) [0]=0; return 0;} For (i=maxstart;i<maxcount+maxstart;i++) (*POUTPUTSTR) [i-maxstart]=intputstr[i];(*poutputstr) [i-maxstart]=0;/ /cout<<*poutputstr<<endl;return Maxcount;} int main () {char *ss=null; Continumax (&ss, "Hgjfgjfgjh");//return 0;}
Find the longest consecutive number string