编译错误,求助+壶关

B3843 [GESP202306 三级] 密码合规

xibaby @ 2024-06-27 21:55:58

#include<bits/stdc++.h>
using namespace std;
int xx,dx,sz,ts,i,j,k; string s1,s[17];
int main(){
    cin>>s1;
    while(i<s1.size())
      if(s1[i]==','){
          k++,s[k]=str.substr(j,i-1-j);
          j=i+1;
      }
    for(i=1;i<=k;i++){
        xx=dx=sz=ts=0;
        for(j=0;j<s[i].size();j++){
            if(islower(s[i][j])) xx=1;
            if(isupper(s[i][j])) dx=1;
            if(isdigit(s[i][j])) sz=1;
            if(s[i][j]=='!'||s[i][j]=='@'
              ||s[i][j]=='#'||s[i][j]=='$')
              ts=1;
        }
        if(((xx&&dx)||(xx&&sz)||(dx&&sz))&&ts)
          cout<<s[i]<<endl;
    }
    return 0;
}

by fire_and_sweets @ 2024-06-28 00:17:23

@xibaby 第 8 行的 str 没有定义,导致 CE


by fjj54188 @ 2024-06-28 21:09:58

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

}

|