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

密码验证合格程序

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

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner fzhinput = new Scanner(System.in);
        
        while (fzhinput.hasNextLine()) {
            boolean result = true;
            boolean ff = true;
            int a = 0, b = 0, c = 0, d = 0, sz = 0;

            String fzhpassword = fzhinput.nextLine();


            if (fzhpassword.length() <= 8 || fzhpassword.contains(" ")) {
                result = false;
            }


            for (int i = 0; i < fzhpassword.length(); i++) {
                char ch = fzhpassword.charAt(i);

                if (ch >= 'A' && ch <= 'Z') {
                    a = 1;
                } else if (ch >= 'a' && ch <= 'z') {
                    b = 1;
                } else if (ch >= '0' && ch <= '9') {
                    c = 1;
                } else {
                    d = 1; 
                }
            }

            sz = a + b + c + d;

            Set<String> stackstore = new HashSet<>();
            for(int i=0;i<fzhpassword.length()-2;i++){
                for(int l=3;i+l<=fzhpassword.length();l++ ){
                    String zfc = fzhpassword.substring(i,i+l);
                    if(stackstore.contains(zfc)){
                        ff=false;
                    }
                    stackstore.add(zfc);
                    
                }

            }
            



            if (sz >= 3 && result && ff) {
                System.out.println("OK");
            } else {
                System.out.println("NG");
            }
        }
    }
}

全部评论

相关推荐

Twilight_m...:还是不够贴近现实,中关村那块60平房子200万怎么可能拿的下来,交个首付还差不多
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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