牛客网--密码验证合格程序(Java)

题目描述

密码要求:

1.长度超过8位

2.包括大小写字母.数字.其它符号,以上四种至少三种

3.不能有相同长度超2的子串重复

说明:长度超过2的子串

输入描述:

 

一组或多组长度超过2的子符串。每组占一行

输出描述:

 

如果符合要求输出:OK,否则输出NG

示例1

输入

复制

021Abc9000
021Abc9Abc1
021ABC9000
021$bc9000

输出

复制

OK
NG
NG
OK

代码:

import java.util.*;
public class Main{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext())
        {
            String x = sc.nextLine();
            if(x.length()<=8)
            {
                System.out.println("NG");
            }else {
                int a=0,b=0,c=0,d=0;//a:大写  b:小写  c:数字  d:其他符号
                for(int i=0;i<x.length();i++) {
                    if(x.charAt(i)>='A'&&x.charAt(i)<='Z') {
                        a=1;
                    }else if(x.charAt(i)>='a'&&x.charAt(i)<='z') {
                        b=1;
                    }else if(x.charAt(i)>='0'&&x.charAt(i)<='9') {
                        c=1;
                    }else {
                        d=1;
                    }
                    if(a+b+c+d>=3) {
                        break;
                    }
                }
                if(a+b+c+d<3) {
                    System.out.println("NG");
                }else {
                    boolean t = true;
                    for(int i=0;i<x.length()-3;i++)
                    {
                        String str1 = x.substring(i,i+3);
                        String str2 = x.substring(i+3,x.length());
                        if(str2.contains(str1)) {
                            System.out.println("NG");
                            t = false;
                            break;
                        }
                    }
                    if(t) {
                        System.out.println("OK");
                    }
                }
            }
        }
    }
}

发布了307 篇原创文章 · 获赞 9 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/hx1043116928/article/details/105294088