Seven_tc @ 2024-04-25 22:24:21
#include <iostream>
#include <iomanip>
#include <sstream>
using namespace std;
int cnt_a, cnt_A, cnt_1, cnt_ch, cnt_bad;
string s, a;
int main() {
cin >> s;
for (auto& c : s) {
if (c == ',')
c = ' ';
}
stringstream ss(s);
while (ss >> a) {
cnt_a = 0, cnt_A = 0, cnt_1 = 0, cnt_ch = 0, cnt_bad = 0;
if (a.length() <= 12 && a.length() >= 6) {
for (auto &c : a) {
if (isalpha(c)) {
cnt_a = 1;
} else if (isupper(c)) {
cnt_A = 1;
} else if (isdigit(c)) {
cnt_1 = 1;
} else if (c == '!' || c == '#' || c == '@' || c == '$') {
cnt_ch = 1;
} else {
cnt_bad = 1;
}
}
if (cnt_bad) continue;
if ((cnt_a + cnt_A + cnt_1 >= 2) && cnt_ch) {
cout << a << endl;
}
}
}
return 0;
}
by elpsconr @ 2024-04-25 23:46:37
isalpha判断的是所有字母,不论大小写。ABCD@!可以hack
by elpsconr @ 2024-04-25 23:49:17
ABCD@!aa是可以作为密码的,而你这个代码却输不出来
by Seven_tc @ 2024-04-27 13:57:32
@elpsconr 太厉害啦
#include <iostream>
#include <iomanip>
#include <sstream>
using namespace std;
int cnt_a, cnt_A, cnt_1, cnt_ch, cnt_bad;
string s, a;
int main() {
cin >> s;
for (char& c : s) {
if (c == ',')
c = ' ';
}
stringstream ss(s);
while (ss >> a) {
cnt_a = 0, cnt_A = 0, cnt_1 = 0, cnt_ch = 0, cnt_bad = 0;
if (a.length() <= 12 && a.length() >= 6) {
for (char &c : a) {
if (islower(c)) {
cnt_a = 1;
} else if (isupper(c)) {
cnt_A = 1;
} else if (isdigit(c)) {
cnt_1 = 1;
} else if (c == '!' || c == '#' || c == '@' || c == '$') {
cnt_ch = 1;
} else {
cnt_bad = 1;
}
}
if (cnt_bad) continue;
if ((cnt_a + cnt_A + cnt_1 >= 2) && cnt_ch) {
cout << a << endl;
}
}
}
return 0;
}