求调

B3843 [GESP202306 三级] 密码合规

Axolotl_awa @ 2024-02-23 13:31:40

#include <iostream>
#include <string>
using namespace std;
bool b[10];
int a[10];
int _end[10],start[10];

bool B3843(int start,int end_,int len,string str) {
    bool boo[3] = {0};
    if(len > 12 || len < 6) {
        return false;
    }
    for(int i = start + 1; i <= end_; i++) {
        if(str[i] >= '0' && str[i] <= '9') {
            boo[0] = true;
        }
        if(str[i] >= 'A' && str[i] <= 'Z') {
            boo[1] = true;
        }
        if(str[i] >= 'a' && str[i] <= 'z') {
            boo[2] = true;
        }
        if(str[i] == '!' || str[i] == '#' || str[i] == '@' || str[i] == '$') {
            boo[3] = true;
        }
        else {
            return false;
        }
    }
    if(boo[3] == false) {
        return false;
    }
    if(boo[0] + boo[1] + boo[2] < 2) {
        return false;
    }
    return true;
}

int main() {
    string str;
    cin >> str;
    start[0] = 0;
    int sum = 0;
    long long len = str.length();
    for(int i = 0; i < len; i++) {
        if(str[i] == ',') {
            _end[sum] = i - 1;
            b[sum] = B3843(start[sum],_end[sum],_end[sum] - start[sum] + 1,str);
            start[++sum] = i + 1;
        }
    }
    _end[sum] = len - 1;
    b[sum] = B3843(start[sum],_end[sum],_end[sum] - start[sum] + 1,str); 
    for(int i = 0; i <= sum; i++) { // 从0到4,共5个
        if(b[i] == true) {
            for(int j = start[i]; j <= _end[i]; j++) {
                cout << str[j];
            }
            cout << endl;
        }
    }
}

by 浅入深出 @ 2024-02-23 13:52:05

#include <iostream>
#include <string>
using namespace std;
bool b[10];
int a[10];
int _end[10],start[10];

bool B3843(int start,int end_,int len,string str) {
    bool boo[4] = {0};// here 1
    if(len > 12 || len < 6) {
        return false;
    }

    // here 2
    for(int i = start + 1; i <= end_; i++) {
        if(str[i] >= '0' && str[i] <= '9') {
            boo[0] = true;
        }
        else if(str[i] >= 'A' && str[i] <= 'Z') {
            boo[1] = true;
        }
        else if(str[i] >= 'a' && str[i] <= 'z') {
            boo[2] = true;
        }
        else if(str[i] == '!' || str[i] == '#' || str[i] == '@' || str[i] == '$') {
            boo[3] = true;
        }
        else {
            return false;
        }
    }
    if(boo[3] == false) {
        return false;
    }
    if(boo[0] + boo[1] + boo[2] < 2) {
        return false;
    }
    return true;
}

int main() {
    string str;
    cin >> str;
    start[0] = 0;
    int sum = 0;
    long long len = str.length();
    for(int i = 0; i < len; i++) {
        if(str[i] == ',') {
            _end[sum] = i - 1;
            b[sum] = B3843(start[sum],_end[sum],_end[sum] - start[sum] + 1,str);
            start[++sum] = i + 1;
        }
    }
    _end[sum] = len - 1;
    b[sum] = B3843(start[sum],_end[sum],_end[sum] - start[sum] + 1,str); 
    for(int i = 0; i <= sum; i++) { // ´Ó0µ½4£¬¹²5¸ö
        if(b[i] == true) {
            for(int j = start[i]; j <= _end[i]; j++) {
                cout << str[j];
            }
            cout << endl;
        }
    }
}

by 浅入深出 @ 2024-02-23 13:54:00

首先是 boo 数组开小了,然后 B3843 函数里的那组 if 语句有逻辑缺陷,你的写法的效果是“如果不是那四个字符就 return false”


by 浅入深出 @ 2024-02-23 14:03:27

还有一点我代码里没改,B3843 函数里的 for 循环的起始值 i = start + 1,这题数据很水 加不加都AC,但事实上不应该加,因为这样等于说跳掉了第一个字符的判断,随便一个数据一试便知:

#2rw

这个数据理论上应当输出。


by Axolotl_awa @ 2024-02-23 14:23:59

@浅入深出 谢谢


|