Question 25th:
Write a function whose prototype is int Continumax (char *outputstr,char *intputstr)
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: When the first address of "abcd12345ed125ss123456789" is passed to Intputstr, the function returns 9,
Outputstr refers to a value of 123456789
Idea: Two pointers, one to save the current longest length of the variable max, and then move the pointer until the end of the string
1 PackageCom.rui.microsoft;2 3 Public classtest25_findlongestdigitstring {4 5 Public Static voidMain (string[] args) {6String s = "ABCD12345ED125SS12345678900ADB11";7 intMax =find (s);8 System.out.println (max);9 }Ten One Public Static intFind (String s) { A if(NULL= = S | | S.isempty ())return0; - Char[] chars =S.tochararray (); - intMax = 0; the intStart = 0, cur = 0; - intLen =chars.length; - while(Cur <Len) { - while(cur < len &&!)isdigit (Chars[cur])) { +cur++; - } +Start =cur; A while(Cur < len &&isdigit (Chars[cur])) { atcur++; - } -max = max > (cur-start)? Max: (cur-start); - } - - returnMax; in } - to Private Static BooleanIsDigit (Charc) { + returnC >= ' 0 ' && C <= ' 9 '; - } the}
Microsoft Algorithm 100 25 Find the longest consecutive number string