读入一个字符串str,输出字符串str中的连续最长的数字串

import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        String str = sc.next();

        char[] array = str.toCharArray();
        int l=0,r=0;
        int maxL = l, maxR = r;
        int max = 0;

        while(r != array.length){
            if(l == r){
                if(array[l] >= 'a' && array[l] <= 'z'){
                    l++;
                    r++;
                }else{
                    r++;
                }
            }else{
                if(array[r] >= 'a' && array[r] <= 'z'){
                    if(r-l > max){
                        max = r-l;
                        maxL = l;
                        maxR = r;
                    }
                    l = r;               
                }else{
                    r++;
                    if(r == array.length){
                        if(r-l > max){
                            max = r-l;
                            maxL = l;
                            maxR = r;
                        }
                    }
                }
            }
        }
        for(int i=maxL; iarray[i]);
        } 
    }   
}

你可能感兴趣的:(算法)