kingsleykingsley @ 2024-07-31 10:46:28
#include <iostream>
using namespace std;
bool check(string s)
{
bool flag1 = 0, flag2 = 0, flag3 = 0, flag4 = 0;
for(int i = 0; i < s.size(); i++)
{
if('0' <= s[i] && s[i] <= '9') flag1 = 1;
else if('a' <= s[i] && s[i] <= 'z') flag2 = 1;
else if('A' <= s[i] && s[i] <= 'Z') flag3 = 1;
else if(s[i] == '!' || s[i] == '@' || s[i] == '#' || s[i] == '$') flag4 = 1;
else return 0;
}
int cnt = 0;
if(flag1) cnt++;
if(flag2) cnt++;
if(flag3) cnt++;
if(s.size() < 6) return 0;
if(s.size() > 9) return 0;
if(cnt <= 1) return 0;
if(flag4 == 0) return 0;
return 1;
}
string st[105];
int top;
int main()
{
string s, temp = "";
cin >> s;
for(int i = 0; i < s.size(); i++)
{
if(s[i] == ',') {st[++top] = temp; temp = "";}
else temp += s[i];
}
st[++top] = temp;
for(int i = 1; i <= top; i++) if(check(st[i])) cout << st[i] << endl;
return 0;
}
by LiXinLong_LXL @ 2024-07-31 10:54:49
题目说
密码最短长度 6 个字符,密码最大长度 12 个字符
那你里面判断字符长度是不是错了?
by LiXinLong_LXL @ 2024-07-31 10:59:04
改成
if(s.size() < 5) return 0;
if(s.size() > 11) return 0;
by lelaimc @ 2024-08-03 17:47:45
@kingsleykingsley
if('0' <= s[i] && s[i] <= '9') flag1 = 1;
else if('a' <= s[i] && s[i] <= 'z') flag2 = 1;
else if('A' <= s[i] && s[i] <= 'Z') flag3 = 1;
else if(s[i] == '!' || s[i] == '@' || s[i] == '#' || s[i] == '$') flag4 = 1;
else return 0;
如果一串字符``` 114514WA!
输入后 它只能检测出```
('0' <= s[i] && s[i] <= '9')
但这串字符是合规的 并且``` if(s.size() < 6) return 0; if(s.size() > 9) return 0;
是不对的
还有
int top;
此处的```
top
未归0,导致出错