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

密码验证合格程序

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

#include <algorithm>
#include <bits/stdc++.h>
#include <vector>
using namespace std;

int main() {
    string password;
    while(cin>>password){
        if(password.size()<8){
            cout<<"NG"<<endl;
            continue;
        }
        int a=0;
        int A=0;
        int number=0;
        int others=0;
        for (auto& ch:password) {
            if (ch>='a'&&ch<='z') {
                a = 1;
            }else if (ch>='A'&&ch<='Z') {
                A = 1;
            }else if (isdigit(ch)) {
                number = 1;
            }else {
             others = 1;
            }
        }

        if (a + A + number + others <3) {
            cout << "NG"<<endl;
            continue;
        }

        vector<vector<int>> dp(password.size()+1, vector<int>(password.size()+1,0));
        int maxLen = 0;
        for (int i=1; i<=password.size(); i++) {
            for (int j=1; j<=password.size(); j++) {
                if(j!=i&&password[i]==password[j]){
                    dp[i][j]=dp[i-1][j-1] + 1;
                    maxLen = max(maxLen, dp[i][j]);
                }else {
                    dp[i][j]=0;
                }
            }
        }

        if(maxLen>2){
            cout << "NG"<<endl;
            continue;
        }
        cout<<"OK"<<endl;
        
    }

}
// 64 位输出请用 printf("%lld")

全部评论

相关推荐

06-05 19:46
已编辑
武汉大学 后端
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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