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 |
Package Com.oj5;import Java.util.scanner;public class Main {public static void main (string[] args) {Scanner in = n EW Scanner (system.in); String str = in.nextline (); int[] length = new int[str.length ()]; int[] begin = New int[str.length ()]; int pos = 0; int count = 0; Boolean beginflag = false; for (int i = 0;i < Str.length (); i++) if (Str.charat (i) <= ' 9 ' &&str.charat (i) >= ' 0 ' &&beginflag== False) {Beginflag = true; count++; Begin[pos] = i; }else if (Str.charat (i) <= ' 9 ' &&str.charat (i) >= ' 0 ') {count++; }else if (beginflag==true&& (Str.charat (i) < ' 0 ' | | Str.charat (i) > ' 9 ')) {length[pos++] = count; Count = 0; Beginflag = false; } if (beginflag==true) length[pos++] = count; int max = 0; for (int i = 0;i < pos; i++) if (length[i]>max) max = Length[i]; if (max==0) {System.out.println (0); return; } for (int i = 0;i < pos; i++) if (Length[i]==max{for (int j = Begin[i];j < Begin[i]+length[i]; j + +) System.out.print (Str.charat (j)); System.out.print (","); } System.out.print (max+ "\ n"); }}
Find the longest consecutive number string