题解 | #在字符串中找出连续最长的数字串#
在字符串中找出连续最长的数字串
https://www.nowcoder.com/practice/2c81f88ecd5a4cc395b5308a99afbbec
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner fzhinput = new Scanner(System.in);
while(fzhinput.hasNextLine()){
String zfc = fzhinput.nextLine();
StringBuilder stack = new StringBuilder();
StringBuilder stack1 = new StringBuilder();
StringBuilder stack2 = new StringBuilder();
String zzzfc="",zzzfc1="";
int num = 0,max=0,num1=0,max1=0;
for(int i=0;i<zfc.length();i++){
char ch = zfc.charAt(i);
if(Character.isDigit(ch)){
num++;
stack.append(zfc.charAt(i));
}
else{
num=0;
stack.setLength(0);
}
if(max<num){
max=num;
zzzfc = stack.toString();
}
}
for(int i=0;i<zfc.length();i++){
char ch = zfc.charAt(i);
if(Character.isDigit(ch)){
num1++;
stack1.append(zfc.charAt(i));
}
else{
num1=0;
stack1.setLength(0);
}
if(num1==max&&!stack1.equals(stack)){
stack2.append(stack1);
stack1.setLength(0);
}
}
zzzfc1=stack2.toString();
System.out.println(zzzfc1+","+max);
}
}
}