题解 | #密码强度等级#

密码强度等级

https://www.nowcoder.com/practice/52d382c2a7164767bca2064c1c9d5361

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.stream.IntStream;
import java.util.stream.Stream;

import static java.util.Arrays.*;
import static java.util.stream.Stream.*;


public class Main {
    public static void main(String[] args) throws IOException {

       //testCompletePack();
        testTh();
    }

    private static void testTh() throws IOException {
        BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
        String str;
        while ((str=bf.readLine())!=null){
            int length = str.length();
            int score=0;
            if (length<=4){
                score=score+5;
            }else if (length<=7){
                score=score+10;
            }else {
                score=score+25;
            }
            int flagA=0;
            int flagB=0;
            int flagN=0;
            int flagC=0;
            char[] chars = str.toCharArray();
            for (char aChar : chars) {
                if (aChar>='a'&&aChar<='z'){
                    flagA=1;
                }else if (aChar>='A'&&aChar<='Z'){
                    flagB=1;
                } else if (aChar>='0'&&aChar<='9') {
                    flagN++;
                }else {
                    flagC++;
                }
            }
            if (flagA==1&&flagB==1){
                score=score+20;
            } else if (flagA==1||flagB==1) {
                score=score+10;
            }
            if (flagN==1){
                score=score+10;
            }else if (flagN>1){
                score=score+20;
            }
            if (flagC==1){
                score=score+10;
            } else if (flagC>1) {
                score=score+25;
            }
            if (flagA==1&&flagB==1&&flagN>=1&&flagC>=1){
                score=score+5;
            } else if ((flagA==1||flagB==1)&&flagC>=1&&flagN>=1) {
                score=score+3;
            } else if ((flagA==1||flagB==1)&&flagN>=1) {
                score=score+2;
            }
            if (score>=0&&score<25){
                System.out.println("VERY_WEAK");
            } else if (score<50) {
                System.out.println("WEAK");
            } else if (score<60) {
                System.out.println("AVERAGE");
            } else if (score<70) {
                System.out.println("STRONG");
            } else if (score<80) {
                System.out.println("VERY_STRONG");
            } else if (score<90) {
                System.out.println("SECURE");
            }else {
                System.out.println("VERY_SECURE");
            }
        }

    }




}

全部评论

相关推荐

不愿透露姓名的神秘牛友
07-04 14:23
点赞 评论 收藏
分享
05-16 11:16
已编辑
东华理工大学 Java
牛客73769814...:盲猜几十人小公司,庙小妖风大,咋不叫她去4️⃣呢😁
牛客创作赏金赛
点赞 评论 收藏
分享
鬼迹人途:你去投一投尚游游戏,服务器一面,第一个图算法,做完了给你一个策略题,你给出方案他就提出低概率问题,答不上当场给你挂
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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