题解 | #密码验证合格程序#

密码验证合格程序

https://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841

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

bool isCorrect(string str) {
    if (str.size() <= 8) {
        return false;
    }
    int capital = 0;
    int small = 0;
    int num = 0;
    int other = 0;
    for (int i = 0; i < str.size(); i++) {
        int temp = (int)str[i];
        if (temp >= 65 && temp <= 90) {
            capital = 1;
        } else if (temp >= 97 && temp <= 122) {
            small = 1;
        } else if (temp >= 48 && temp <= 57) {
            num = 1;
        } else {
            other = 1;
        }
    }
    if (capital+small+num+other < 3) {
        return false;
    }
    for (int i=0; i<str.size()-5; i++) {
        string tmp1 = str.substr(i,3);
        for(int j=i+3; j<str.size()-2; j++){
            string tmp2 = str.substr(j,3);
            if(tmp1==tmp2){
                return false;
            }
        }
    }
    return true;
}
int main() {
    string input;
    while (getline(cin, input)) {
        istringstream s(input);
        string str;
        getline(s, str, ' ');
        if(isCorrect(str)){
            cout<<"OK"<<endl;
        }else {
            cout<<"NG"<<endl;
        }
    }
}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

09-28 22:01
已编辑
广西科技大学 IT技术支持
合适才能收到offe...:找桌面运维?
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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