求助大佬,到底哪个样例过不了

B3843 [GESP202306 三级] 密码合规

ahuahua @ 2025-01-10 20:21:41


#include <iostream>
#include <vector>

using namespace std;

bool check(string s) {
    if (6 > s.size() || s.size() > 12) return false;

    bool b1, b2, b3, b4;
    for (int i = 0; i < s.size(); i ++) {
        if ('a' <= s[i] && s[i] <= 'z') b1 = true;
        else if ('A' <= s[i] && s[i] <= 'Z') b2 = true;
        else if ('0' <= s[i] && s[i] <= '9') b3 = true;
        else if (s[i] == '!' || s[i] == '@' || s[i] == '#' || s[i] == '$') b4 = true;
        else return false;
    }

    return (b1 + b2 + b3 >= 2) && b4;
}

int main() {
    string s;
    cin >> s;

    vector<string> res;
    string tmp;
    for (int i = 0; i < s.size(); i ++) {
        if (s[i] != ',') tmp += s[i];
        else {
            res.push_back(tmp);
            tmp.clear();
        }
    }
    res.push_back(tmp);

    int t = 0;
    for (int i = 0; i < res.size(); i ++) {
        if (check(res[i])) {
            if (!t) {
                cout << res[i];
                t ++;
            }
            else cout << endl << res[i];
        }
    }   

    return 0;
}

by baiguifan_ @ 2025-01-10 20:48:10

函数里定义的b1b4需要赋初值吧


by laijinqi1006 @ 2025-01-10 20:49:31

@ahuahua b1 b2 b3 b4清零


by ahuahua @ 2025-01-10 22:39:31

@laijinqi1006 感谢


by ahuahua @ 2025-01-10 22:39:44

@baiguifan_ 感谢


|