样例对,但评测是WA,只有一个评测点

B3843 [GESP202306 三级] 密码合规

DerrickDong @ 2024-09-04 10:11:34

求助!!!

#include<bits/stdc++.h>
using namespace std;
char a[10010];
char b[10010];
bool is() {
    int len= strlen(b);
    bool te = false;//是否有特殊字符
    int has1 = 0;//是否有数字
    int has2 = 0;//是否有小写字母
    int has3 = 0;//是否有大写字母
    if (len<6||len>12)
    {
        return false;
    }
    for(int i = 0;i<len;i++)
    {
        if(isdigit(b[i]))
        {
            has1 = 1;
        }
        else if(islower(b[i]))
        {
            has2 = 1;
        }
        else if(isupper(b[i]))
        {
            has3 = 1;
        }
        if(b[i] == '!'||b[i] == '@'||b[i] == '#'||b[i] == '$')
        {
            te = true;
        }
        if((has1+has2+has3)>=2)
        {
            return true;
        }
    }
    if(!(te))
    {
        return false;
    }
    return (has1+has2+has3)>=2;
}
int main() {
    cin>>a;
    int cur = 0;
    for(int i = 0;i<strlen(a);i++)
    {
        if(a[i] == ',')
        {
            if(is())
            {
                b[cur] = '\0';
                cout<<b<<endl;
                cur = 0;
                continue;
            }
        }
        else
        {
            b[cur] = a[i];
            cur++;
        }
    }
    return 0;
}

by wangqixiang36 @ 2024-09-04 19:07:07

AC代码!

#include <bits/stdc++.h>
using namespace std;
set<char> se;
void solve(string t){
    int len = t.size();
    if (len < 6 || len > 12){
        return;
    }
    set<int> ans;
    for (int i = 0; i < len; i++){
        if (se.count(t[i]) == 0){
            return;
        }
        if (t[i] >= 'a' && t[i] <= 'z'){
            ans.insert(1);
        }
        else if (t[i] >= 'A' && t[i] <= 'Z'){
            ans.insert(2);
        }
        else if (t[i] >= '0' && t[i] <= '9'){
            ans.insert(4);
        }
        else{
            ans.insert(8);
        }
    }
    if (ans.count(8) == 0){
        return;
    }
    if (ans.size() < 3){
        return;
    }
    cout << t << "\n";
}
void init(){
    string s = "!@#$";
    for (int i = 0; i < 4; i++){
        se.insert(s[i]);
    }
    for (int i = 0; i < 10; i++){
        se.insert('0' + i);
    }
    for (int i = 0; i < 26; i++){
        se.insert('A' + i);
        se.insert('a' + i);
    }
}
signed main(){
    init();
    string s, t = "";
    getline(cin, s);
    int len = s.size();
    for (int i = 0; i < len; i++){
        if (s[i] == ','){
            solve(t);
            t = "";
        }
        else{
            t += s[i];
        }
    }
    if (t.size()){
        solve(t);
    }
    return 0;
}

by DerrickDong @ 2024-09-04 20:28:23

@wangqixiang36 收到,已关注


|