0分求助!!

B3843 [GESP202306 三级] 密码合规

__NanFeng__ @ 2024-08-29 15:37:08

求大神指点!!!

#include<iostream>
#include<string>
using namespace std;

string a, b;
bool da = 0, xiao = 0, num = 0, te = 0;

bool check(string b)
{
    if((b.size() >= 6) && (b.size() <= 12))
    {
        for(char d : b)
        {
            if((d >= 97 && d <= 122) || (d >= 65 && d <= 90) || (d >= 48 && d <= 57) || (d == '@') || (d == '!') || (d == '#') || (d == '$'))
            {

                if(d >= 97 && d <= 122) xiao = 1;
                else if(d >= 65 && d <= 90) da = 1;
                else if(d >= 48 && d <= 57) num = 1;

                else if(d == '@') te = 1;
                else if(d == '!') te = 1;
                else if(d == '#') te = 1;
                else if(d == '$') te = 1;
                else return 0;

                if(te == 1)
                {
                    if((da == 1 && xiao == 1) || (da == 1 && num == 1) || (xiao == 1 && num == 1))
                    {
                        return 1;
                    }
                    else return 0;
                }
            }
            else return 0;
        }
    }
    else return 0;
}

int main()
{
    cin >> a;
    a += ',';
    for(char c : a)
    {
        if(c != ',')
        {
            b += c;
        }
        else
        {
            if(check(b) == 1) cout << b << endl;
            b = "";
        }
    }
    return 0;
}

by chenxinyao @ 2024-08-29 15:39:40

#include<iostream>
#include<string>

string s;
int halpha = 0, hlow = 0, hup = 0, hnum = 0;
void check(char c){
    if(c == '!' || c == '@' || c == '#' || c == '$') halpha = 1;
    if(c >= 'a' && c <= 'z') hlow = 1;
    if(c >= 'A' && c <= 'Z') hup = 1;
    if(c >= '0' && c <= '9') hnum = 1;
    //return (hlow + hup + hnum) >= 2 && halpha;
}

using namespace std;
int main(){
    cin >> s;
    int l = s.size();
    bool can1 = false;
    if(l >= 6 && l <= 12) can1 = true;
    s += ',';
    string ans = " ";

    for(char c : s){
        if(c != ','){
            check(c);
            ans += c;
        } 
        else{
            if((hlow + hup + hnum) >= 2 && halpha){

            }
        }
    }
    return 0;
} 

by wanchenhao @ 2024-08-29 15:40:12

@NanFeng

AC代码求关

#include<iostream>
using namespace std;
char line[101];
char pwd[101];
bool check(char * str, int l) {
    if (l < 6 || l > 12)
    return false;
    bool hasC = false, hasL = false, hasD = false, hasS = false;
    for (int i = 0; str[i] != '\0'; i++) {
        if ('A' <= str[i] && str[i] <= 'Z') {
            hasC = true;

        } else if ('a' <= str[i] && str[i] <= 'z') {
            hasL = true;

        } else if ('0' <= str[i] && str[i] <= '9') {
            hasD = true;

        } else if (str[i] == '!' || str[i] == '@' ||str[i] == '#' || str[i] == '$') {
            hasS = true;

        } else
        return false;

    }if (!hasS)
    return false;
    if (hasC + hasL + hasD < 2)
    return false;
    return true;

}
int main() {
    cin >> line;
    int len = 0;
    for (int i = 0; line[i] != '\0'; i++) {
        if (line[i] != ',') {
            pwd[len] = line[i];len++;

        } else {
            pwd[len] = '\0';
            if (check(pwd, len))
            cout << pwd << endl;len = 0;

        }

    }if (len > 0) {
        pwd[len] = '\0';
        if (check(pwd, len))
        cout << pwd << endl;

    }return 0;

}

by __NanFeng__ @ 2024-08-29 15:46:01

@wanchenhao 已AC,感谢大神!!!


|