lx01220122 @ 2024-10-04 11:23:02
#include<bits/stdc++.h>
using namespace std;
int n=1;
bool t,s,dz,xz,bol;
int main(){
string ss,a[10005];
cin>>ss;
for(int i=0;i<ss.size();i++){
if(ss[i]==','){
n++;
}else{
a[n]+=ss[i];
}
}
for(int i=1;i<=n;i++){
for(int j=0;j<a[i].size();j++){
if(a[i][j]>='0'&&a[i][j]<='9'){
s=1;
}else if(a[i][j]>='a'&&a[i][j]<='z'){
xz=1;
}else if(a[i][j]>='A'&&a[i][j]<='Z'){
dz=1;
}else if(a[i][j]=='!'||a[i][j]=='@'||a[i][j]=='#'||a[i][j]=='$'){
t=1;
}else{
bol=1;
}
}
if(a[i].size()<=12&&a[i].size()>=6&&bol!=1){
if(t==1){
if(xz==1&&dz==1){
cout<<a[i]<<endl;
}else if(xz==1&&s==1){
cout<<a[i]<<endl;
}else if(dz==1&&s==1){
cout<<a[i]<<endl;
}
}
}
}
return 0;
}
by Peter_Li @ 2024-10-04 13:29:33
@lx01220122
对每个密码都应重置标志位:
// 重置标志位
s = xz = dz = t = bol = 0;
最小改动代码如下:
#include<bits/stdc++.h>
using namespace std;
int n = 1;
bool t, s, dz, xz, bol;
int main() {
string ss, a[10005];
cin >> ss;
for (int i = 0; i < ss.size(); i++) {
if (ss[i] == ',') {
n++;
} else {
a[n] += ss[i];
}
}
for (int i = 1; i <= n; i++) {
// 重置标志位
s = xz = dz = t = bol = 0;
for (int j = 0; j < a[i].size(); j++) {
if (a[i][j] >= '0' && a[i][j] <= '9') {
s = 1;
} else if (a[i][j] >= 'a' && a[i][j] <= 'z') {
xz = 1;
} else if (a[i][j] >= 'A' && a[i][j] <= 'Z') {
dz = 1;
} else if (a[i][j] == '!' || a[i][j] == '@' || a[i][j] == '#' || a[i][j] == '$') {
t = 1;
} else {
bol = 1;
}
}
if (a[i].size() <= 12 && a[i].size() >= 6 && bol != 1) {
if (t == 1) {
if (xz == 1 && dz == 1) {
cout << a[i] << endl;
} else if (xz == 1 && s == 1) {
cout << a[i] << endl;
} else if (dz == 1 && s == 1) {
cout << a[i] << endl;
}
}
}
}
return 0;
}