题解 | #密码强度等级#

密码强度等级

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

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

int main() {
    string strInput;
    while (getline(cin, strInput)) { // 注意 while 处理多个 case
        int score = 0;
        size_t leng = strInput.length();
        if (leng <= 4) {
            score += 5;
        } else if (leng <= 7) {
            score += 10;
        } else {
            score += 25;
        }

        int numCount = 0, lowerCount = 0, supperCount = 0, specialCount = 0;
        for (int i = 0; i < leng; i++) {
            if (isdigit(strInput.at(i))) {
                numCount++;
            } else if (islower(strInput.at(i))) {
                lowerCount++;
            } else if (isupper(strInput.at(i))) {
                supperCount++;
            } else if (ispunct(strInput.at(i))) {
                specialCount++;
            }
        }

        if (lowerCount != 0 && supperCount != 0) {
            score += 20;
        } else if (lowerCount != 0 || supperCount != 0) {
            score += 10;
        }

        if (numCount > 1) {
            score += 20;
        } else if (numCount == 1) {
            score += 10;
        }

        if (specialCount > 1) {
            score += 25;
        } else if (specialCount == 1) {
            score += 10;
        }

        if (numCount > 0) {
            if (specialCount > 0) {
                if (lowerCount > 0 && supperCount > 0) {
                    score += 5;
                } else if (lowerCount > 0 || supperCount > 0) {
                    score += 3;
                }
            } else if (lowerCount > 0 || supperCount > 0) {
                score += 2;
            }
        }

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

全部评论

相关推荐

WhiteAlbum...:学院本2中大厂垂直实习➕acm比赛 秋招0面试
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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