题解 | 密码强度检查

密码强度检查

https://www.nowcoder.com/practice/40cc4cfe4a7d45839393fc305fc5609e

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int T = Integer.parseInt(scanner.nextLine()); // 读取整行,不然存在换行符不被读进去的问题
        
        for (int i = 0; i < T; i++) {
            String s = scanner.nextLine();
            if (s.length() < 8) {
                System.out.println("Weak");
            } else {
                int lower = 0, upper = 0, num = 0, special = 0;
                for (char c : s.toCharArray()) {
                    if (Character.isDigit(c)) num = 1;
                    else if (Character.isUpperCase(c)) upper = 1;
                    else if (Character.isLowerCase(c)) lower = 1;
                    else if (c >= 33 && c <= 126) special = 1;
                }
                int sum = lower + upper + num + special;
                System.out.println(sum == 4 ? "Strong" : (sum == 3 ? "Medium" : "Weak"));
            }
        }
    }
}

全部评论

相关推荐

点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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