Describe: |
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, do 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: Unsignedint Continumax (char** poutputstr, char* intputstr) Input parameters: char* intputstr input string; Output parameters: char** Poutputstr: The longest consecutive number string, if the length of the longest consecutive number string is 0, an empty string should be returned, and an empty string should be returned if the input string is empty; return value: The length of the longest consecutive number string |
/* 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* INTP
UTSTR 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 point to the memory should be within the function with the malloc function request, the call is responsible for releasing Return value: The length of the longest consecutive number string */unsigned int continumax (char** poutputstr, char* intputstr) {bool isdigiit = false;
Whether the string has a number int i = 0, maxLength = 0, beginindex = 0;
int currlength = 0,currindex = 0; /* Iterate through the input string */for (i = 0; Intputstr[i]! = '; i++) {/* Find characters that are numbers */if (Intputstr[i] >= ' 0 ' && intputs
Tr[i] <= ' 9 ') {currlength = 0;
Isdigiit = true;
Currindex = i;
while (intputstr[i]! = ' ' && (intputstr[i] >= ' 0 ' && intputstr[i] <= ' 9 ')) {i++;
currlength++;
} if (Currlength >= maxLength) {maxLength = Currlength;
Beginindex = Currindex;
}}}/* If the string does not have a number */if (isdigiit = = False) {*poutputstr = ""; } else {(*POUTPUTSTR) = (char*) mAlloc (maxLength + 1);
memset ((*POUTPUTSTR), 0, maxLength + 1);
strncpy_s (*POUTPUTSTR, MaxLength + 1, intputstr + beginindex, maxLength); (*POUTPUTSTR)
[MaxLength] = ' + ';
} return maxLength; }