Huawei OD computer test-find the longest consecutive number string in a string (C++ & Java & JS & Python)

describe

Input a string, return its longest numeric substring, and its length. If there are multiple longest numeric substrings, output them all (according to the relative position of the original string)

This question contains multiple sets of sample inputs.

Data range: String length 1≤�≤200 1≤n≤200, ensuring that each input group contains at least one number

Enter description:

Enter a string. 1<=len(string)<=200

Output description:

Output the longest digit string in the string and its length, separated by commas. If there are strings of the same length, they should be output together (without spaces in the middle).

Example 1

enter:

abcd12345ed125ss123058789
a8a72a6a5yy98y65ee1r2

Output:

123058789,9
729865,2

illustrate:

In Example 1, the longest numeric substring is 123058789, with a length of 9
In Example 2, the longest number substrings are 72, 98, and 65, all with a length of 2    

Java:

import java.io.*;
import java.util.*;

public class Main{
    public static void main(String[] args) throws Exception{
        Scanner sc = new Scanner(System.in);

        while(sc.hasNextLine()){
            String line = sc.nextLine();
            String[] ss = line.split("[^0-9]&#

Guess you like

Origin blog.csdn.net/m0_68036862/article/details/132895194