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

密码验证合格程序

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

import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNextLine()) {
            String str = sc.nextLine();
            if (str.length() <= 8) {
                System.out.println("NG");
                continue;
            }
            char A = 'A', a = 'a', num = '0', other = 'O';
            Set<Character> set = new HashSet<>();
            for (int i = 0; i < str.length(); i++) {
                if (str.charAt(i) >= 'A' && str.charAt(i) <= 'Z') {
                    set.add('A');
                } else if (str.charAt(i) >= 'a' && str.charAt(i) <= 'z') {
                    set.add('a');
                } else if (str.charAt(i) >= '0' && str.charAt(i) <= '9') {
                    set.add('0');
                } else {
                    set.add('O');
                }
            }
            if (set.size() < 3) {
                System.out.println("NG");
                continue;
            }
            List<String> list = new ArrayList<>();
            Set<String> set1 = new HashSet<>();
            for (int i = 0; i < str.length() - 2; i++) {
                for (int j = i + 2; j < str.length(); j++) {
                    if (j == str.length() - 1){
                        list.add(str.substring(i));
                        set1.add(str.substring(i));
                    }else{
                        list.add(str.substring(i,j+1));
                        set1.add(str.substring(i,j+1));
                    }
                }
            }
            if(list.size() == set1.size()){
                System.out.println("OK");
            }else{
                System.out.println("NG");
            }
        }
    }
}
全部评论

相关推荐

牛客98820962...:个人意见,我觉得实习和项目经历要一致,达美乐感觉没必要写
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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