Huawei OJ: Find the longest consecutive number string

Source: Internet
Author: User
Tags function prototype string back

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; }



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.