【十二题解】 | #密码验证合格程序#
密码验证合格程序
http://www.nowcoder.com/practice/184edec193864f0985ad2684fbc86841
这个很简单,一个一个条件判断就行了,只是记住在判断三个条件是否同时成立的时候,第三个条件一定要放在最后并且是用&&短路,因为如果数据小于八个放进第三个条件判断就会报错
#include<stdio.h>
int f_max(int a, int b){
return a>b?a:b;
}
int one(int start, int end){
return end-start>7?1:0;
}
int two(char*password, int start, int end){
int typea =0;
int typeA =0;
int type1 =0;
int typeother = 0;
for(;start<=end; start++){
if(password[start]>='a' && password[start]<='z'){
typea = 1;
}
else if(password[start]>='A' && password[start]<='Z'){
typeA = 1;
}
else if(password[start]>='0' && password[start]<='9'){
type1 = 1;
}
else{
typeother = 1;
}
}
return type1+typeA+typea+typeother>=3?1:0;
}
int three(char*password, int start, int end){
int sub_lenth = 0;
for(int i=start; i<end-4; i++){
for(int j=i+1; j<=end; j++){
if(password[i]==password[j]){
int k = i;
int l = j;
while(password[k]==password[l] && l<=end && k<j){
l++;
k++;
}
sub_lenth=f_max(sub_lenth, l-j);
}
}
}
return sub_lenth>2?0:1;
}
int main(){
char password[10000];
char*loc=password;
while(~scanf("%c", loc))loc++;
int lenth = (loc-password)/sizeof(char);
int i, j;
for(i=0; i<lenth; i=j+1){
for(j=i; password[j]!='\n'; j++){
if(password[j+1]=='\n'){
int a=one(i, j);
int b = two(password, i, j);
int c = three(password, i, j);
if(one(i, j) && two(password, i, j) && three(password, i, j))
{
printf("OK\n");
}
else{
printf("NG\n");
}
}
}
}
return 0;
}