HELP!! 0pts

B3843 [GESP202306 三级] 密码合规

abssortpow1145145 @ 2024-11-25 19:15:32


#include <bits/stdc++.h>
using namespace std;
int main()
{
    string a,t="";
    cin >> a;
    a+=',';
    for(int i=0;i<a.size();i++)
    {
        if(a[i]==',')
        {
            int flag=1;
            if(t.size()<6 || t.size()>12)
            {
                flag=0;
            }
            int s=0,d=0,x=0,te=0;
            for(int j=0;j<t.size();j++)
            {
                if(a[j]>='0' && a[j]<='9')
                {
                    s=1;
                }
                else if(a[j]>='A' && a[j]<='Z')
                {
                    d=1;
                }
                else if(a[j]>='a' && a[j]<='z')
                {
                    x=1;
                }
                else if(a[j]=='!' || a[j]=='@' || a[j]=='#' || a[j]=='$')
                {
                    te=1;
                }
                else
                {
                    flag=0;
                }
            }
            if(s+d+x>=2 && flag==1 && te==1)
            {
                cout << t << endl;
            }
        }
        else
        {
            t+=a[i];
        }
    }
    return 0;
}

by Zq123321 @ 2024-12-01 15:51:31

你的t是不是再次循环没有清空


by caoyichen1 @ 2024-12-01 16:48:54

#include<bits/stdc++.h>
using namespace std;
bool judge_whether_the_password_is_compliant(string m,int t)
{
    if (t<6||t>12)
    {
        return 0;
    }
    bool does_the_capital_letter_match=0,do_lowercase_letters_match=0,does_the_figure_match=0,does_the_special_character_match=0;
    for (int i=0;m[i]!='\0';i++)
    {
        if (m[i]>='A'&&m[i]<='Z')
        {
            does_the_capital_letter_match=1;
        }
        else if(m[i]>='a'&&m[i]<='z')
        {
            do_lowercase_letters_match=1;
        }
        else if(m[i]>='0'&&m[i]<='9')
        {
            does_the_figure_match=1;
        }
        else if(m[i]=='!'||m[i]=='@'||m[i]=='#'||m[i]=='$')
        {
            does_the_special_character_match=1;
        }
        else
        {
            return 0;
        }
    }
    if (!does_the_special_character_match||does_the_capital_letter_match+do_lowercase_letters_match+does_the_figure_match<2)
    {
        return 0;
    }
    return 1;
}
int main()
{
    char n[102],m[102];
    int t=0;
    cin>>n;
    for (int i=0;n[i]!='\0';i++)
    {
        if (n[i]!=',')
        {
            m[t]=n[i];
            t++;
        }
        else
        {
            m[t]='\0';
            if (judge_whether_the_password_is_compliant(m,t))
            {
                cout<<m<<endl;
            }
            t=0;
        }
    }
    if (t>0)
    {
        m[t]='\0';
        if (judge_whether_the_password_is_compliant(m,t))
        {
            cout<<m;
        }
    }
    return 0;
}

|