样例已过,为何WA了

B3843 [GESP202306 三级] 密码合规

Float_fish @ 2023-12-05 23:27:05

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

string arr[1210], s, str;
char ch;
int cnt, len;
bool check(string s){
    int b1 = 0, b2 = 0, b3 = 0, b4 = 0;
    int len = s.size();
    if (len <= 6 || len >= 12) return false;
    for (int i = 0; i < len; i++){
        if ('A' <= s[i] && s[i] <= 'Z'){
            b1 = 1;
            continue;
        }
        if ('a' <= s[i] && s[i] <= 'z'){
            b2 = 1;
            continue;
        }
        if ('0' <= s[i] && s[i] <= '9'){
            b3 = 1;
            continue;
        }
        if (s[i] == '!' || s[i] == '@' || s[i] == '#' || s[i] == '$'){
            b4 = 1;
            continue;
        }
        return false;
    }
    if (b1 + b2 + b3 >= 2 && b4) return true;
    return false;
}
int main(){
    getline(cin, str);
    int l = str.size();
    for (int i = 0; i < l; i++){
        if (str[i] != ','){
            arr[cnt] += str[i];
        } else {
            cnt++;
        }
    }
    for (int i = 0; i < cnt; i++){
        s = arr[i];
        if (check(s)) cout << s << endl;        
    }
    return 0;
}

by AlexanderC @ 2023-12-31 09:59:15

按照题目意思,密码的长度可以等于6和12


|