口令的分类
内存限制: 256 Mb时间限制: 1000 ms
题目描述
给定一串字符序列,请检查它是否符合成为口令的条件,并判断它的强弱。一个合规的口令,需要满足以下两个必要条件:
- 长度至少为 8,至多为 16。
- 只包含以下类型的字符
- 大写字母。
- 小写字母。
- 数字。
- 标点符号。符合要求的标点符号如下:
# & ' ^ " _ = ~ ? ! , . ; : + - *%/|\()[]{}<>
如果一个字符序列包含上述四种字符中的至少三种,则称之为强口令,否则称之为弱口令
输入格式
若干个字符,表示一个有待验证的字符串,保证每个字符都是可见字符,保证不会出现空格或换行。
输出格式
- 如果输入的密码串不合规,输出
Invalid password
- 合规但密码较弱,输出
Weak password
- 否则,输出
Strong password
样例数据
输入:
123456!Aa
输出:
Strong password
解析:模拟,详见代码
#include <bits/stdc++.h>
using namespace std;
string f="#&'^\"_=~?!,.;:+-*%/|\()[]{}<>";//定义其他字符,注意双引号前要加转义符\
string s;
int main() {
cin>>s;
int u=0;//大写字母
int l=0;//小写字母
int d=0;//数字
int o=0;//其他字符
int len=s.length();
if (len<8||len>16){//长度判断
cout<<"Invalid password";
return 0;
}
for (int i=0;i<len;i++){
if (isupper(s[i])){//如果是大写字符
u=1;
}else if (islower(s[i])){//如果是小写字符
l=1;
}else if (isdigit(s[i])){//如果是数字
d=1;
}else if(f.find(s[i])!=s.npos){//如果是其他字符
o=1;
}else{//如果都不是
cout<<"Invalid password";
return 0;
}
}
if (u+l+d+o>=3){//判断强度
cout<<"Strong password";
}else{
cout<<"Weak password";
}
return 0;
}