题解 | #密码强度等级#

密码强度等级

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

package main

import (
    "fmt"
)

func main() {
    var input string
    fmt.Scan(&input)
    var res int
    // 长度测试
    length:=len(input)
    switch{
        case length<=4:
        res+=5
        case 5<=length&&length<=7:
        res+=10
        case length>=8:
        res+=25
    }
    // 字母方面的测试
    low:=false
    upper:=false
    num:=0
    sign:=0
    for _,v:=range input{
        if v>='a'&&v<='z'{
            low=true
        }else if v>='A'&&v<='Z'{
            upper=true
        }else if v>='0'&&v<='9'{
            num++
        }else{
            sign++
        }
    }
    if low&&upper{
        res+=20
    }else if low||upper{
        res+=10
    }
    // 第三关数字测试
    if num==1{
        res+=10
    }
    if num>1{
        res+=20
    }
    // 第四关
    if sign==1{
        res+=10
    }
    if sign>1{
        res+=25
    }
    // 第五关
    if (low&&upper)&&(num>=1)&&(sign>=1){
        res+=5
    }else if (low||upper)&&(num>=1)&&(sign>=1){
        res+=3
    }else if(low||upper)&&(num>=1){
        res+=2
    }
     switch {
        case res >= 90:
        fmt.Println("VERY_SECURE")
        case res < 90 && res >= 80:
        fmt.Println("SECURE")
        case res < 80 && res >= 70:
        fmt.Println("VERY_STRONG")
        case res < 70 && res >= 60:
        fmt.Println("STRONG")
        case res < 60 && res >= 50:
        fmt.Println("AVERAGE")
        case res < 50 && res >= 25:
        fmt.Println("WEAK")
        case res < 25 && res >= 0:
        fmt.Println("VERY_WEAK")
    }
}

全部评论

相关推荐

暴杀流调参工作者:春招又试了一些岗位,现在投递很有意思,不仅要精心准备简历,投递官网还得把自己写的东西一条一条复制上去,阿里更是各个bu都有自己的官网,重复操作无数次,投完简历卡完学历了,又该写性格测评、能力测评,写完了又要写专业笔试,最近还有些公司搞了AI辅助编程笔试,有些还有AI面试,对着机器人话也听不明白录屏硬说,终于到了人工面试又要一二三四面,小组成员面主管面部门主管面hr面,次次都没出错机会,稍有不慎就是挂。 卡学历卡项目卡论文卡实习什么都卡,没有不卡的😂
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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