0分?

B3843 [GESP202306 三级] 密码合规

ja_son @ 2024-06-20 10:21:48

#include <bits/stdc++.h>
using namespace std;

string a;
int x;

int main() {
    cin >> a;
    int lens = a.size();
    for (int i = 0; i < lens; i += x) {
        string b="";
        bool tf = false;
        int c[2] = {0, 0};
        while (a[x] != ',') {
            b += a[x];
            if (a[x] >= 'a' && a[x] <= 'z') {
                c[0] = 1;
            } else if (a[x] >= 'A' && a[x] <= 'Z') {
                c[0] += 1;
            } else if (a[x] == '!' || a[x] == '@' || a[x] == '#' || a[x] == '$') {
                c[1] += 1;
            } else if (a[x] >= '0' && a[x] <= '9') {
                c[0] += 1;
            } else {
                tf = true;
                break;
            }
            x++;
        }
        x++;
        if (tf) {
            continue;
        }
        if (b.size() < 6 || b.size() > 12) {
            continue;
        }
        if (c[0] < 2 || c[1] == 0) {
            continue;
        }
        cout << b << endl;
    }
    return 0;
}

by Estelle_N @ 2024-06-20 10:54:00

@ja_son 判断条件不对,小写,大写,数字应该出现至少两种,而不是出现两个。for 中应该为 i = x

#include <bits/stdc++.h>
using namespace std;

string a;
int x;

int main() {
    cin >> a;
    int lens = a.size();
    for (int i = 0; i < lens; i = x) {
        string b="";
        bool tf = false;
        int c[4] = {0, 0, 0, 0};
        while (a[x] != ',') {
            b += a[x];
            if (a[x] >= 'a' && a[x] <= 'z') {
                c[0] = 1;
            } else if (a[x] >= 'A' && a[x] <= 'Z') {
                c[1] = 1;
            } else if (a[x] == '!' || a[x] == '@' || a[x] == '#' || a[x] == '$') {
                c[3] = 1;
            } else if (a[x] >= '0' && a[x] <= '9') {
                c[2] = 1;
            } else {
                tf = true;
                break;
            }
            x++;
        }
        x++;
        if (tf) {
            continue;
        }
        if (b.size() < 6 || b.size() > 12) {
            continue;
        }
        if (c[0] + c[1] + c[2] < 2 || c[3] == 0) {
            continue;
        }
        cout << b << endl;
    }
    return 0;
}

by ja_son @ 2024-06-20 11:11:34

@Estelle_N 感谢,已AC


|