题解 | #密码验证合格程序#

密码验证合格程序

http://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841

import java.util.*;
import java.util.regex.*;
public class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        while(scan.hasNext()){
            String str = scan.nextLine();
            if(str.length()<=8){
                System.out.println("NG");
                continue;
            }
            if(getMatch(str)){
                System.out.println("NG");
                continue;
            }
            if(getString(str, 0, 3)){
                System.out.println("NG");
                continue;
            }
            System.out.println("OK");
        }
        scan.close();
    }
    public static boolean getMatch(String str){
        int count = 0;
        Pattern p1 = Pattern.compile("[0-9]");
        if(p1.matcher(str).find()){
            count++;
        }
        Pattern p2 = Pattern.compile("[a-z]");
        if(p2.matcher(str).find()){
            count++;
        }
        Pattern p3 = Pattern.compile("[A-Z]");
        if(p3.matcher(str).find()){
            count++;
        }
        Pattern p4 = Pattern.compile("[^0-9a-zA-Z]");
        if(p4.matcher(str).find()){
            count++;
        }
        if(count>=3){
            return false;
        }
        else{
            return true;
        }
    }
    
    public static boolean getString(String str, int l, int r){
        if(r>str.length()){
            return false;
        }
        if(str.substring(r).contains(str.substring(l,r))){
            return true;
        }
        else{
            return getString(str,l+1,r+1);
        }
    }
}












全部评论

相关推荐

07-04 16:00
门头沟学院 Java
点赞 评论 收藏
分享
迟缓的斜杠青年巴比Q...:简历被投过的公司卖出去了,我前两天遇到过更离谱的,打电话来问我有没有意向报班学Java学习,服了,还拿我学校一个学长在他们那报班学了之后干了华为OD当招牌
点赞 评论 收藏
分享
05-09 13:22
门头沟学院 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务