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

密码验证合格程序

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");
			}
			
		}
		
	}

}

全部评论

相关推荐

10-30 19:23
已编辑
山东大学(威海) C++
牛至超人:其实简历是不需要事无巨细的写的,让对方知道你有这段经历就行了,最重要的是面试的时候讲细讲明白
点赞 评论 收藏
分享
notbeentak...:就抓,嗯抓,开不开匿名都要抓,一点坏事不让说,就对公司顶礼膜拜佩服的五体投地就对了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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