密码包含字符 数字 大写字母 小写字母四种类型,长度在8-120.若长度不对,输出1,类型不对,输出0,正常输出2.
#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
int check(char *str)//判断是否是符合要求的密码
{
int len;
len=strlen(str);
if(len<8||len>120)
return 1;
int s=0,f=0,b=0,a=0;
int sum=0;
for(int j=0;j<len;j++)
{
if(str[j]>=33&&str[j]<=47)//符号
f=1;
else if(str[j]>=48&&str[j]<=57) //数字
s=1;
else if(str[j]>=65&&str[j]<=90)//大写字母
b=1;
else
a=1;
}
sum=a+b+s+f;
if(sum==4)
return 0;
else
return 2;
}
int main ()
{
char password[1000]={};//数组定义要初始化!!,不然调用strlen函数长度会出错
gets(password);
int num=0,j=0,c;
char word[120]={};
num=strlen(word);
num=strlen(password);
for(int i=0;i<num+1;i++)
{
if(password[i]==' '||password[i]=='\0')
{
c=check(word);
printf("%d\r\n",c);
j=0;
}
word[j++]=password[i];
}
system("pause");
return 0;
}