Describe |
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 |
Knowledge points |
Bit arithmetic |
Run time limit |
10M |
Memory limit |
128 |
Input |
Enter a string. |
Output |
The longest numeric string in the output string and its length. If the numeric string is empty, only 0 is output such as Input:dadfsaf output:0 |
Sample input |
abcd12345ed125ss123058789 |
Sample output |
123058789,9 |
Import Java.util.Scanner;
public class main{public static void Main (string[] args) {Scanner sc = new Scanner (system.in);
String input = Sc.next ();
Int[] result = new int[input.length ()];
Sc.close (); for (int i = 0; i < input.length (); i++) {if (Input.charat (i) >= ' 0 ' && input.charat (i) <= ' 9 ') {//Times
The calendar determines whether the number int is length = 0; for (; i < input.length (); i++) {//If it is a number, start from this position to the back to traverse if (Input.charat (i) >= ' 0 ' && input.charat (i) &L t;= ' 9 ') {length++; When it is a number, the length +1} else {break; Otherwise end-break traversal} result[i] = length;
I is the position where the string ends, length is the number string length}}} int length = 0;
int temp = 0; for (int i = 0; i < result.length; i++) {if (Result[i] >= length) {length = Result[i];
Find the longest number string and its end position temp = i;
}} if (length = = 0) System.out.println (0);
else {String output = input.substring (temp-length + 1, temp + 1);
SYSTEM.OUT.PRINTLN (Output + "," + length); }
}
//Method Two: Use split mates with regular expressions to separate strings into arrays containing only numbers, this method is only suitable for input strings that contain only characters and numbers private static void find (String input) {string[] string = input
. Split ("[A-za-z]");
String temp = null;
int length = 0;
for (int i = 0; i < string.length; i++) {if (length <= string[i].length ()) {length = String[i].length ();
temp = String[i];
}} if (string.length = = 0) System.out.println (0);
else System.out.println (temp + "," + length); }
}