您的位置:首页 > 其它

蓝桥杯2017正则匹配

2020-07-14 06:35 435 查看

正则问题:
/正则问题,例如(xx|xxx)xx|xxxx,输出正则表达式能接收的最大的字符串长度是多少/

package com.lanqiao2017;

import java.util.Scanner;

/*正则问题,例如(xx|xxx)xx|xxxx,输出正则表达式能接收的最大的字符串长度是多少*/

public class zhengze {
static char[]a;
static int pos=0;
static int len;

public static int f() {
int tmp=0;
int m=0;
while(pos<len){
if(a[pos]=='(') {
pos++;
tmp+=f();

}else if(a[pos]=='x') {

pos++;
tmp++;

}else if(a[pos]=='|') {

pos++;
m=Math.max(m, tmp);
tmp=0;

}else if(a[pos]==')') {

pos++;
m=Math.max(m,tmp);
return m;
}
}

m=Math.max(m, tmp);

return m;

}

public static void main(String arg[]) {
Scanner sc=new Scanner(System.in);
String line=sc.nextLine();
a=line.toCharArray();
len=a.length;
System.out.println(f());
}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: