?我样例输入进去怎么出来了……一堆换行???

B3843 [GESP202306 三级] 密码合规

Somnus_Love @ 2024-06-21 19:56:13

(shooting__star)

#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int l=s.length();
    string s2="";
    for(int i=0;i<l;i++)
    {
        if(s[i]==',')
        {
            int l2=s2.length();
            bool f1=0,f2=0,f3=0,f4=0;
            if(l2<6||l2>12)
            {
                continue;
            }
            for(int j=0;j<l2;j++)
            {
                if(s2[j]>='a'&&s2[j]<='z')
                {
                    f1=1;
                }
                else if(s2[j]>='A'&&s2[j]<='Z')
                {
                    f2=1;
                }
                else if(s2[j]>='0'&&s2[j]<='9')
                {
                    f3=1;
                }
                else if(s2[j]=='!'||s2[j]=='@'||s2[j]=='#'||s2[j]=='$')
                {
                    f4=1;
                }
                if(f1+f2+f3>=2&&f4)
                {
                    cout<<s2<<endl;
                }
                s2="";
            }
        }
        else
        {
            s2+=s[i];
        }
    }
    return 0;   
}

by Somnus_Love @ 2024-06-21 20:01:03

(shooting__star)好家伙,发现就在判断完之后,字符串空了,判断前是好好的,这又是什么情况


by Somnus_Love @ 2024-06-21 20:04:03

(shooting__star)

好了,这下换行只剩一个,然后:啥也没有了(

#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int l=s.length();
    string s2="";
    for(int i=0;i<l;i++)
    {
        if(s[i]==',')
        {
//          cout<<s2<<endl;
            int l2=s2.length();
            bool f1=0,f2=0,f3=0,f4=0;
            if(l2<6||l2>12)
            {
                continue;
            }
            for(int j=0;j<l2;j++)
            {
                if(s2[j]>='a'&&s2[j]<='z')
                {
                    f1=1;
                }
                else if(s2[j]>='A'&&s2[j]<='Z')
                {
                    f2=1;
                }
                else if(s2[j]>='0'&&s2[j]<='9')
                {
                    f3=1;
                }
                else if(s2[j]=='!'||s2[j]=='@'||s2[j]=='#'||s2[j]=='$')
                {
                    f4=1;
                }
                if(f1+f2+f3>=2&&f4)
                {
                    cout<<s2<<endl;
                }
                s2="";
                l2=0;
            }
        }
        else
        {
            s2=s2+s[i];
//          cout<<s2<<endl;
        }
    }
    return 0;
}

by Ivan422 @ 2024-06-21 20:04:10

@Somnus_Love

你看看你输出下面第 2 行是不是有点问题。


by Somnus_Love @ 2024-06-21 20:05:28

@Ivan422 啊?


by Ivan422 @ 2024-06-21 20:07:34

@Somnus_Love

这不是清空 s2 了吗


by Ivan422 @ 2024-06-21 20:08:46

@Somnus_Love

要是清空了,之后就没法继续判断了。

把判定部分挪出来外面啊。


by Somnus_Love @ 2024-06-21 20:09:30

@Ivan422 哥们我自己还抓出了点儿别的问题,,,

#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int l=s.length();
    string s2="";//存放每个密码
    for(int i=0;i<=l;i++)
    {
        if(s[i]==','||i==l)
        {
//          cout<<s2<<endl;
            int l2=s2.length();
            int f1=0,f2=0,f3=0,f4=0;
            if(l2<6||l2>12)
            {
                cout<<"";
            }
            for(int j=0;j<l2;j++)
            {
                if(s2[j]>='a'&&s2[j]<='z')
                {
                    f1=1;
                }
                else if(s2[j]>='A'&&s2[j]<='Z')
                {
                    f2=1;
                }
                else if(s2[j]>='0'&&s2[j]<='9')
                {
                    f3=1;
                }
                else if(s2[j]=='!'||s2[j]=='@'||s2[j]=='#'||s2[j]=='$')
                {
                    f4=1;
                }
                cout<<f1<<endl;
                cout<<f2<<endl;
                cout<<f3<<endl;
                cout<<f4<<endl;
                if(f1+f2+f3>=2&&f4)
                {
                    cout<<s2<<endl;
                }
                s2="";//清空,存下一个密码
                l2=0;
            }
        }
        else
        {
            s2=s2+s[i];
//          cout<<s2<<endl;
        }
    }
    return 0;
}

by Somnus_Love @ 2024-06-21 20:11:00

@Ivan422 哦哦哦我搞错了,因为开始我大括号都乱套了,不小心的(?


by Somnus_Love @ 2024-06-21 20:12:34

#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int l=s.length();
    string s2="";
    for(int i=0;i<=l;i++)
    {
        if(s[i]==','||i==l)
        {
//          cout<<s2<<endl;
            int l2=s2.length();
            int f1=0,f2=0,f3=0,f4=0;
            if(l2<6||l2>12)
            {
                cout<<"";
            }
            for(int j=0;j<l2;j++)
            {
                if(s2[j]>='a'&&s2[j]<='z')
                {
                    f1=1;
                }
                else if(s2[j]>='A'&&s2[j]<='Z')
                {
                    f2=1;
                }
                else if(s2[j]>='0'&&s2[j]<='9')
                {
                    f3=1;
                }
                else if(s2[j]=='!'||s2[j]=='@'||s2[j]=='#'||s2[j]=='$')
                {
                    f4=1;
                }
            }
            if(f1+f2+f3>=2&&f4)
            {
                cout<<s2<<endl;
            }
            s2="";
            l2=0;
        }
        else
        {
            s2=s2+s[i];
//          cout<<s2<<endl;
        }
    }
    return 0;
}

这下样例4个密码都出来了


by Ivan422 @ 2024-06-21 20:13:07

@Somnus_Love

?


| 下一页