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

密码验证合格程序

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

讲一下最后一个条件,不能含有长度大于2的不含有公共元素的重复子串,这句话意思是含有公共元素的重复子串是OK的,暴力解法的话直接遍历两个for验证长度是3的情况,因为长度更大的是3的子集。

#include <string>
#include <map>
#include <vector>
#include <cctype>

using namespace std;

int main() {
    string str, result;
    
    while (cin >> str) {
        bool lowalpha = false, upalpha = false, digit = false, other = false;
        bool changed = false;
        if (str.size() > 8) {
            for (int i = 0; i < str.size(); i++) {
                if (islower(str[i])) lowalpha = true;
                if (isupper(str[i])) upalpha = true;
                if (isdigit(str[i])) digit = true;
                if (ispunct(str[i])) other = true;
            }
            if (lowalpha & upalpha & digit & other ||
                lowalpha & upalpha & digit || upalpha & digit & other ||
                lowalpha & digit & other) {
                for(int i =0;i<str.size()-6;i++){
                    for(int j= i+3;j<str.size()-3;j++){
                        
                        if((str[i]==str[j])&&(str[i+1]==str[j+1])&&
                           (str[i+2]==str[j+2])){
                        result ="NG";changed=true;}
                    }
                }
                if(!changed) result = "OK";
                
            }
            else result ="NG";


        }
        else result = "NG";
        cout<<result<<endl;

    }


}
全部评论

相关推荐

哞客37422655...:兄弟别慌!💪 民办本找实习确实难点,但不是没机会。100+简历才2个面试,可能简历需要优化下: 项目经历写具体点,突出测试用例、bug数量等 技能栏把测试工具/方法论写清楚 可以考虑降低预期,先进小厂积累经验 测试岗相对好进,坚持投!现在才半个月,有人投3个月才上岸的😭 加油,offer在路上了🚀
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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