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

密码验证合格程序

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

/****************
** fgets更安全,注意条件判断完整
*****************/
#include<stdio.h>
#include<string.h>

int main()
{
    char str[101];
    int flag = 0, len = 0;
    int i,j;
    while( fgets( str, 101,stdin ) )
    {
        len = strlen(str);
        flag = 1;
        int count[4]={0};
        if( len < 9 )
            flag = 0;
        else
        {
            for( int i = 0; i<len; i++ )
            {
                if( str[i] >= 'a' && str[i] <= 'z' )
                    count[0] = 1;
                else if( str[i] >= 'A' && str[i] <= 'Z' )
                    count[1] = 1;
                else if( str[i] >= '0' && str[i] <= '9' )
                    count[2] =1;
                else if( str[i] != ' ' && str[i] != '\n' )
                    count[3] = 1;
            }
            if( count[0] + count[1] + count[2] + count[3] < 3 )
                flag = 0;
            else
            { 
                for( i = 0; i < len - 6; i++ )
                {
                    for( j = i+3; j < len - 3; j++ )
                    {
                        if( str[j] == str[i] && str[j+1] == str[i+1] && str[j+2] == str[i+2] )
                            flag = 0;
                    }
                }

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

    }
    return 0;
}

全部评论

相关推荐

05-16 11:16
已编辑
东华理工大学 Java
牛客737698141号:盲猜几十人小公司,庙小妖风大,咋不叫她去4️⃣呢😁
点赞 评论 收藏
分享
求offer的大角牛:不吃香菜
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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