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

密码验证合格程序

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

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNext()) { // 注意 while 处理多个 case
            System.out.println(check(in.nextLine()) ? "OK" : "NG");
        }
    }

    public static boolean check(String pswd){
        if(pswd.length() <= 8) return false;
        int counte = 0;
        int countE = 0;
        int countN = 0;
        int countS = 0;
        /*for(int i=0; i<pswd.length(); i++){
            char c = pswd.charAt(i);
            if(c>='0' && c<='9') countN++;
            else if(c>='a' && c<='z') counte++;
            else if(c>='A' && c<='Z') countE++;
            else if(c != ' ' || c == '\n') countS++;
        }
        if((counte>0 && countE>0 && countN>0) 
        || (counte>0 && countE>0 && countS>0)
        || (counte>0 && countN>0 && countS>0)
        || (countE>0 && countN>0 && countS>0)
        || (counte>0 && countE>0 && countN>0 && countS>0)){
            return reStr(pswd);
        }*/
        for(int i=0; i<pswd.length(); i++){
            char c = pswd.charAt(i);
            if(c>='0' && c<='9') countN=1;
            else if(c>='a' && c<='z') counte=1;
            else if(c>='A' && c<='Z') countE=1;
            else if(c != ' ' || c == '\n') countS=1;
        }
        if(counte+countE+countN+countS >= 3) return reStr(pswd);
        return false;
    }

    private static boolean reStr(String s) {
        for (int i=3; i<s.length(); i++) {
            if (s.substring(i).contains(s.substring(i-3, i))) {
                return false;
            }
        }
        return true;
    }
}

全部评论

相关推荐

不愿透露姓名的神秘牛友
昨天 14:48
点赞 评论 收藏
分享
搜索部&nbsp;首先说下timeline8.18,投递8.19,约一面8.21,晚上一面call约二面8.22,上午二面下午oc周末等待(8.23,8.24)8.25,offer一年前,我还是懵懵懂懂,高考完的暑假,只会提前学学高数,未来的画像是什么?我或许无法预测。开学后,自学Python,接单,无数个客户的ddl,偷偷摸摸一个人找自习的地方,这一步步竟然为后来的我,搭建工程能力的基础。大一上,我也要感谢我的第一位老板,让我接触到了实习,师兄带着我一步步入门,看他们写的飞书文档。大一下,导师带我参与企业项目,这让我渐渐发现,应该去实践,增长见识,而非局限当下,盯着自己的小新pro。不久后,第一波投递开始,结果当然是约面极少。盯着简历上的文字和ssob,我开始思考,确实很多可以去提升。带着些许不甘心,继续沉淀,慢慢的约面也越来越多,有的时候两天7场,准备完就接着下一个日程。这一次,也许是刚好到位吧,比较match,面试答的流利,关关难关关过,成为度孝子展望未来,依然是重重挑战,果然只有收到offer的那一刻是开心的。愿在百度星海拆解的每一段代码,都能成为丈量宇宙的诗行;此志终赴星河,而今迈步重铸天阶。屏幕前的你们,在无数个向星海奔赴的日夜,一定一定,会在未来化作群星回响的征程——请永远相信此刻埋首耕耘的自己!!!
一天三顿半:???百度提前批发 offer了?不是统一和正式批排序完再发吗我靠
百度求职进展汇总
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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