题解 | #密码强度等级#

密码强度等级

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

#include <iostream>
#include <string>
using namespace std;

int main() {
    string s;
    getline(cin, s);

    int ans = 0;
    if (s.size() <= 4)
        ans += 5;
    else if (s.size() >= 5 && s.size() <= 7)
        ans += 10;
    else
        ans += 25;

    int bW = 0, sW = 0, nW = 0, eW = 0;
    for (auto c : s) {
        if (c >= 'a' && c <= 'z')
            sW++;
        else if ((c >= 'A' && c <= 'Z'))
            bW++;
        else if (c >= '0' && c <= '9')
            nW++;
        else
            eW++;
    }

    if (bW + sW == 0)
        ans += 0;
    else if (bW != 0 && sW != 0)
        ans += 20;
    else
        ans += 10;

    if (nW == 0)
        ;
    else if (nW == 1)
        ans += 10;
    else
        ans += 20;

    if (eW == 0)
        ;
    else if (eW == 1)
        ans += 10;
    else
        ans += 25;

    if (bW != 0 && sW != 0 && nW != 0 && eW != 0)
        ans += 5;
    else if ((bW != 0 || sW != 0) && nW != 0 && eW != 0)
        ans += 3;
    else if ((bW != 0 || sW != 0) && nW != 0)
        ans += 2;

    if ((ans >= 90) && (ans <= 100)) {
        cout << "VERY_SECURE" << endl;
    } else if ((ans >= 80) && (ans < 90)) {
        cout << "SECURE" << endl;
    } else if ((ans >= 70) && (ans < 80)) {
        cout << "VERY_STRONG" << endl;
    } else if ((ans >= 60) && (ans < 70)) {
        cout << "STRONG" << endl;
    } else if ((ans >= 50) && (ans < 60)) {
        cout << "AVERAGE" << endl;
    } else if ((ans >= 25) && (ans < 50)) {
        cout << "WEAK" << endl;
    } else if ((ans >= 0) && (ans < 25)) {
        cout << "VERY_WEAK" << endl;
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

07-14 13:47
门头沟学院 Java
Lynn012:你评估好自己的位置了吗《顶尖应届》
投递小米集团等公司7个岗位
点赞 评论 收藏
分享
05-29 22:11
门头沟学院 Java
Elastic90:抛开学历造假不谈,这公司的招聘需求也挺怪的,Java开发还要求你有图文识别、移动端开发和c++的经验,有点逆天了。
点赞 评论 收藏
分享
07-17 12:09
门头沟学院 Java
讲的口干舌燥,头都晕了怎么要讲这么长啊
码农索隆:没事,你口干舌燥,他不一定会看,
投递小鹏汽车等公司7个岗位
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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