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

密码验证合格程序

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

#include<stdio.h>
#include<string.h>
int main(){
    int l,k,c,i;//l记录字符串长度,c记录种类,k记录长度超过2子串重复情况
    char str[100];
    while(scanf("%s",str)!=EOF){
        l=strlen(str);
        int big,small,digit,other;
        big=small=digit=other=0;
        for(i=0;i<l;i++){
            if(str[i]>='a' && str[i]<='z')small=1;
            else if(str[i]>='A' && str[i]<='Z')big=1;
            else if(str[i]>='0' && str[i]<='9')digit=1;
            else other=1;
        }
        c=big+small+digit+other;
        //记录长度超过2的子串的重复情况,k=0说明没有重复,k=1说明重复了
        int j;
        for(i=0;i<l-6;i++){
            for(j=i+3;j<l-3;j++)
                if(str[i]==str[j] && str[i+1]==str[j+1] && str[i+2]==str[j+2]){
                    k=1;
                    break;
                }
        }
        if(l>8 && c>=3 && k==0)
            printf("OK");
        else 
            printf("NG");
    }
    return 0;
}

#华为OD机考#
全部评论

相关推荐

评论
点赞
2
分享

创作者周榜

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