RE求助!!

B3843 [GESP202306 三级] 密码合规

chenxinyao @ 2024-08-29 16:30:07

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

string s;
int halpha = 0, hlow = 0, hup = 0, hnum = 0;
bool flag = true;

bool check(char c){
    if(c == '!' || c == '@' || c == '#' || c == '$') halpha = 1;
    else if(c >= 'a' && c <= 'z') hlow = 1;
    else if(c >= 'A' && c <= 'Z') hup = 1;
    else if(c >= '0' && c <= '9') hnum = 1;
    else flag = false;
}

int main(){
    cin >> s;
    s += ',';
    string ans = "";
    for(char c : s){
        if(c != ','){
            check(c);
            ans += c;
        } 
        else{
            int l = ans.size();
            if(l >= 6 && l <= 12){
                if(halpha && flag && (hlow + hup + hnum) >= 2){
                    cout << ans << endl;
                }
            }

            halpha = 0, hlow = 0, hup = 0, hnum = 0, flag = true;
            ans = "";
        }
    }
    return 0;
}

救救孩子吧!!!


by __NanFeng__ @ 2024-08-29 16:32:44

#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;

}

可AC代码,求关


by __mcr130102__ @ 2024-08-29 16:37:29

求关注

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

int main() {
    string s;
    int halpha = 0, hlow = 0, hup = 0, hnum = 0;
    bool flag = true;
    string ans = "";

    // 读取输入
    getline(cin, s);

    // 遍历字符串中的每个字符
    for (char c : s) {
        if (c != ',') {
            // 检查字符并更新计数器
            if (c == '!' || c == '@' || c == '#' || c == '$') halpha = 1;
            else if (c >= 'a' && c <= 'z') hlow = 1;
            else if (c >= 'A' && c <= 'Z') hup = 1;
            else if (c >= '0' && c <= '9') hnum = 1;
            else flag = false;

            // 将字符添加到ans字符串
            ans += c;
        } else {
            // 检查ans字符串的长度和字符条件
            if (ans.length() >= 6 && ans.length() <= 12) {
                if (halpha && (hlow + hup + hnum) >= 2) {
                    cout << ans << endl;
                }
            }
            // 重置计数器和标志
            halpha = 0, hlow = 0, hup = 0, hnum = 0, flag = true;
            // 清空ans字符串
            ans = "";
        }
    }

    // 检查最后一个子字符串
    if (!s.empty() && s.back() != ',') {
        if (ans.length() >= 6 && ans.length() <= 12) {
            if (halpha && (hlow + hup + hnum) >= 2) {
                cout << ans << endl;
            }
        }
    }

    return 0;
}

|