1.长度超过8位
2.包括大小写字母.数字.其它符号,以上四种至少三种
3.不能有相同长度超2的子串重复
明:长度超过2的子串
输入描述:
一组或多组长度超过2的子符串。每组占一行
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#define MAX_BUF 128
#define VALID_LEN 9
#define SAME_MAX_LEN 3
int get_passwd_type(char* str, int len)
{
int num_flag = 0;
int alp_flag = 0;
int oth_flag = 0;
int Alp_flag = 0;
int i;
if (NULL == str){
return 0;
}
if (len < VALID_LEN){
return 0;
}
assert(strlen(str) == len);
for(i=0; i<len; i++){
if (str[i]>='0' && str[i]<='9'){
num_flag = 1;
}
else if (str[i]>='a' && str[i]<='z'){
alp_flag = 1;
}
else if (str[i]>='A' && str[i]<='Z'){
Alp_flag = 1;
}
else{
oth_flag = 1;
}
}
return (num_flag+alp_flag+Alp_flag+oth_flag);
}
int check_same_2len_ret(char* str, int len)
{
int i;
char target[SAME_MAX_LEN+1] = {0};
char* p = NULL;
if (NULL == str){
return 1;
}
if (len < VALID_LEN){
return 1;
}
assert(strlen(str) == len);
for (i=0; i<(len-(SAME_MAX_LEN-1)); i++)
{
strncpy(target, str+i, SAME_MAX_LEN);
p = strstr(str, target);
p += SAME_MAX_LEN;
if ( strstr(p, target) != NULL )
{
return 1;
}
}
return 0;
}
int main(int argc, char* argv[])
{
char buf[MAX_BUF] = {0};
while(gets(buf) != NULL)
{
//printf("buf=%s
", buf);
if (strlen(buf) < VALID_LEN) {
printf("NG
");
}
else if ( get_passwd_type(buf, strlen(buf)) < 3
|| check_same_2len_ret(buf, strlen(buf)) == 1 ) {
printf("NG
");
}
else {
printf("OK
");
}
}
return 0;
}