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

密码验证合格程序

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

import java.util.HashSet;
import java.util.Scanner;

public class HJ20 {
	public static void main(String[] args) {
		Scanner input=new Scanner(System.in);
		while (input.hasNextLine()) {
			String string=input.nextLine();
			if (string.length()>8) {
				int count=0;
				if (string.matches(".*[A-Z].*")) {
					count=count+1;
				}
				if (string.matches(".*[a-z].*")) {
					count=count+1;
				}
				if (string.matches(".*[0-9].*")) {
					count=count+1;
				}
				if (string.matches(".*[^a-zA-Z0-9].*")) {
					count=count+1;
				}
				
//				System.out.println(count);
				if (count>=3) {
					HashSet<String> set=new HashSet<>();
					for (int i = 0; i < string.length()-3; i++) {
						String sub=string.substring(i,i+3);
						if(set.add(sub)) {
							
						}else {
							System.out.println("NG");
							return;
						}
					}
					System.out.println("OK");
				}else {
					System.out.println("NG");
				}
			}
			else {
				System.out.println("NG");
			}
			
		}
		
	}

}

全部评论

相关推荐

认真搞学习:这个真喷不了,你是我见过最美的牛客女孩
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务