0分求助

B3843 [GESP202306 三级] 密码合规

zhaoyikuan @ 2024-09-06 12:57:36

#include<iostream>
using namespace std;
string a;
int main()
{
    cin >> a;
    bool v = true;
    string s = "";
    for(int i = 0; i < a.size(); i++)
    {
        if(a[i]>='0' && a[i]<='9') s += a[i];
        else if(a[i] >= 'A' && a[i] <= 'Z' && v) s += a[i];
        else if(a[i] >= 'a' && a[i] <= 'z' && v) s += a[i];
        else if((a[i] == '!' || a[i] == '@' || a[i] == '#' || a[i] == '$') && v) s += a[i];
        else if(a[i] == ',' && s.size() <= 12 && s != "")
        {
            cout << s << endl;
            s = "";
            v = true;
        }
        else
        {
            s = "";
            v = false;
        }
    }
}

样例对了测试点一个也不对


by zhuhan20120206 @ 2024-09-06 22:11:58


#include<bits/stdc++.h>
using namespace std;
int sum=1;
int a[10];
bool flag=true;
char c;
string s[210];
int main()
{
    while(cin>>c)
    {
        if(c!=',')
            s[sum]+=c;
        else if(c==',')
            sum++;
    }
//  for(int i=1;i<=sum;i++)
//      cout<<s[i]<<" "; 
    for(int k=1;k<=sum;k++)
    {
        bool flag=true;
        memset(a,0,sizeof(a));
        if(s[k].size()<6||s[k].size()>12)
            continue;
        for(int i=0;i<s[k].size();i++)
        {
            if(s[k][i]=='!'||s[k][i]=='@'||s[k][i]=='#'||s[k][i]=='$')
                a[4]=1;
            else if(s[k][i]>='A'&&s[k][i]<='Z')
                a[3]=1;
            else if(s[k][i]>='a'&&s[k][i]<='z')
                a[2]=1;
            else if(s[k][i]>='0'&&s[k][i]<='9')
                a[1]=1;
            else
                break;
        }
        if(flag==true&&a[4]==1&&a[3]==1&&a[2]==1&&a[1]==1)
            cout<<s[k]<<'\n';
        else if(flag==true&&a[4]==1&&a[3]!=1&&a[2]==1&&a[1]==1)
            cout<<s[k]<<'\n';
        else if(flag==true&&a[4]==1&&a[3]==1&&a[2]!=1&&a[1]==1)
            cout<<s[k]<<'\n';
        else if(flag==true&&a[4]==1&&a[3]==1&&a[2]==1&&a[1]!=1)
            cout<<s[k]<<'\n';
    }
    return 0;
}

|