题解 | 密码强度检查

密码强度检查

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

全部评论

相关推荐

一只乌鸦:这不才9月吗,26到明年毕业前能一直找啊,能拿下提前批,转正的,offer打牌的都是有两把刷子的,为什么非要跟他们比。如果别人是9本硕+金牌+好几段大厂实习呢?如果别人是双非通天代呢?如果别人是速通哥呢?,做好自己就行了,我们做不到他们一样提前杀死比赛,但晚点到终点也没啥关系吧
双非应该如何逆袭?
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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