package com.huaweijishi.passwordcheck;
import java.util.Scanner;
/**
* 题目:密码要求:1.长度超过8位2.包括大小写字母.数字.其它符号,以上四种至少三种
* 3.不能有相同长度超2的子串重复
* 输入描述:一组或多组长度超过2的子符串。每组占一行
* 输出描述:如果符合要求输出:OK,否则输出NG
* 实现功能。
* @author hexiaoli
*
*/
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
while (input.hasNextLine()) {
String str = input.nextLine();
System.out.println(checkPassword(str));
}
}
public static String checkPassword(String str) {
String result = "NG";
// 边界1
if (str.length() <= 8) {
return result;
}
// 边界2
// 用一个数组存储大小写字母.数字.其它符号,以上四种情况
int[] situation = new int[4];
int strlength = str.length();
for (int i = 0; i < strlength; i++) {
if (str.charAt(i) >= 'a' && str.charAt(i) <= 'z') {
situation[0] = 1;
}
if (str.charAt(i) >= 'A' && str.charAt(i) <= 'Z') {
situation[1] = 1;
}
if (str.charAt(i) >= '0'
华为机试(20)密码验证合格程序
最新推荐文章于 2025-05-09 18:49:45 发布