求助,代码无法判断'@'
查看原帖
求助,代码无法判断'@'
1302118
Lixtar楼主2024/12/7 20:24

经过测试之后发现,当密码中的特殊字符只含有“@”时,程序无法正确识别,如“seHJ12@”被认为是不合规密码。

代码如下:

#include <iostream>
#include <cstring>
using namespace std;
int head, e, pos;
string s, cnt;

bool solve(string n){
	int a = 0, leng = n.length();
	bool az = 0, AZ = 0, num = 0, sp = 0;
	if (leng < 6 || leng > 12) return false; // length
	for (int i=0; i<leng; i++){
		if (n[i]>='a'&&n[i]<='z') az=1; // a-z
		else if (n[i]>='A'&&n[i]<='Z') AZ=1; // A-Z
		else if (n[i]>='0'&&n[i]<='z') num=1; // 0-9
		else if (n[i]=='@' || n[i]=='!' || n[i]=='#' || n[i]=='$') sp=1; // special
		else return false;
	}
	a = az + AZ + num;
	if (a >= 2 && sp == 1) return true;
	else return false;
}

int main(){
	cin >> s;
	s += ",";
	int len = s.length();
	while (pos != len){
		pos = s.find(",",pos);
		e = pos - head;
		cnt = s.substr(head,e);
		head = pos + 1; pos++;
		if(solve(cnt)) cout << cnt << endl;
	}
	return 0;
} 
2024/12/7 20:24
加载中...