求助大佬 ,样例过了,但wa

B3843 [GESP202306 三级] 密码合规

Faded_wind123 @ 2024-04-04 17:47:36


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

int main() {
    long long big, small, unique, num, a1, a2, a3, a4, f,others;
    string s;
    getline(cin, s); // 读取一行输入
    big = small = unique = num = a1 = a2 = a3 = a4 = f = others=0;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] == ','||i==s.length()-1) {
            if ((big + small + num + unique) >= 6 && (big + small + num + unique) <= 12&&others==0) {
                if (a1 + a2 + a3 >= 2 && a4 == 1) {
                    cout << s.substr(i - f, f) << endl;
                    i+=1;
                }
            }
            big = small = unique = num = a1 = a2 = a3 = a4 = f = 0; // 重置计数器
        }
        else {
            if (s[i] >= 'A' && s[i] <= 'Z') {
                big++;
                a1 = 1;
            }else
            if (s[i] >= 'a' && s[i] <= 'z') {
                small++;
                a2 = 1;
            }else
            if (s[i] >= '0' && s[i] <= '9') {
                num++;
                a3 = 1;
            }else
            if (s[i] == '!' || s[i] == '@' || s[i] == '#' || s[i] == '$') {
                unique++;
                a4 = 1;
            }else{others++;}

        }
        f++;
    }
    return 0;
}

by tysy_020 @ 2024-04-21 12:49:05

#include<bits/stdc++.h>
using namespace std;
int main(){    
    //定义变量,初始化
    string a,b;
    int d,x,s,f,el;
    d=x=s=f=el=0;
    cin>>a;
    a+=','; //给a补充一个',',否则判断不到最后一个
    for(int i=0;i<=a.size();i++){
        //计数
        if(a[i]!=','){
            if(a[i]>='a' && a[i]<='z'){
                x++;
            }
            else if(a[i]>='A' && a[i]<='Z'){
                d++;
            }
            else if(a[i]>='0' && a[i]<='9'){
                s++;
            }
            else if(a[i]=='@' || a[i]=='!' || a[i]=='#' || a[i]=='$'){
                f++;
            }
            //不要忘记判断其他情况
            else{
                el++;
            }
            b+=a[i];
        }
        else{
            b+='\0'; //结尾必须为'\0'
            //调试
            //cout<<d<<" "<<x<<" "<<s<<" "<<f<<" "<<el<<" "<<b<<endl; 
            if(f>=1 && el==0){ //判断
                if((d>0 && s>0) || (x>0 && s>0) || (d>0 && x>0)){
                    if(b.size()>=7 && b.size()<=13){
                        cout<<b<<endl;
                    }
                }
            }
            //重置
            b=""; 
            d=x=s=f=0;
            el=0;
            //重置
        }
    }
    return 0;
}

|