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

密码验证合格程序

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

#include <stdio.h>
#include <string.h>

int repeatCheck(char* str, int index)   //index>2
{
    if(index<5) return 1;
    char repeatChar[3];
    for(int i=0;i<3;i++)    repeatChar[i] = str[index-2+i];
    // repeatChar[0]=str[index-2];
    // repeatChar[1]=str[index-1];
    // repeatChar[2]=str[index];
    for(int i=0;i<=index-3;i++)
    {
        if(repeatChar[0]==str[i]
        && repeatChar[1]==str[i+1]
        && repeatChar[2]==str[i+2])   //出现等于3的连续重复子串
        {
            return 0;
        }
    }
    return 1;
}

int main() {
    char codeStr[100];

    while (scanf("%s", codeStr) != EOF){
        int rightF=0;
        int codeLen = strlen(codeStr);
        if(codeLen<=8) rightF=1;
        else{
            int numF=0, AF=0, aF=0, symF=0; //标志位
            for(int i=0;i<codeLen;i++)
            {
                if(codeStr[i]>='0' && codeStr[i]<='9') numF=1;
                else if(codeStr[i]>='a' && codeStr[i]<='z') aF=1;
                else if(codeStr[i]>='A' && codeStr[i]<='Z') AF=1;
                else symF=1;

                if(!repeatCheck(codeStr,i)) rightF=1;
            }

            if(numF+aF+AF+symF<3) rightF=1;
        }

        if(rightF==0) printf("OK \n");
        else printf("NG \n");
    }
    return 0;
}

全部评论

相关推荐

10-09 16:12
门头沟学院 Java
帅宇殿下:佬,简历写的什么
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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