3.1-OR59 字符串中找出连续最长的数字串
字符串中找出连续最长的数字串_牛客题霸_牛客网 (nowcoder.com)
- import java.util.*;
- public class Main {
- public static void main(String[] args){
- Scanner sc=new Scanner(System.in);
- while(sc.hasNext()){
- String str=sc.nextLine();
- String ret="";
- String cur="";
- int i=0;
- for(;i
- char c=str.charAt(i);
- if(c>='0'&&c<='9'){
- cur=cur+c+"";
- }else{
- if(cur.length()>ret.length()){
- ret=cur;
- }
- cur="";
- }
- }
- if(i==str.length()&&cur.length()>ret.length()){
- ret=cur;
- }
- System.out.println(ret);
- }
- }
- }