题解 | #密码验证合格程序#
密码验证合格程序
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; }