网站提示密码必须由8~16个字符组成可以包含数字、大写字母、小写字母、特殊符号这4种字符类型。注特殊符号只包含! 、、#、$、、^、&、、、、-、+、=以下是三种强度密码的设计规则1包含4种不同类型字符的密码是强密码2包含2种或3种不同类型字符的密码是中等密码3只包含1种类型字符的密码是弱密码。小威利用浏览器自动创建了N个密码请你编写程序判断这些密码的强度输入第一行输入一个正整数N 4N10表示密
#include <iostream>
#include <string>
#include <regex>
using namespace std;
int checkPasswordStrength(string password) {
int count = 0;
regex digit("[0-9]");
regex upper("[A-Z]");
regex lower("[a-z]");
regex special("[!@#$%^&*()-+=]");
if (regex_search(password, digit)) {
count++;
}
if (regex_search(password, upper)) {
count++;
}
if (regex_search(password, lower)) {
count++;
}
if (regex_search(password, special)) {
count++;
}
if (count == 4) {
return 2; // strong password
} else if (count == 2 || count == 3) {
return 1; // medium password
} else {
return 0; // weak password
}
}
int main() {
string code;
cin >> code;
int N;
cin >> N;
for (int i = 0; i < N; i++) {
string password;
cin >> password;
int strength = checkPasswordStrength(password);
cout << strength << endl;
}
return 0;
}
``
原文地址: http://www.cveoy.top/t/topic/i1yh 著作权归作者所有。请勿转载和采集!