我这玩意能过样例,自己搞的数据也行,为什么WA

B3843 [GESP202306 三级] 密码合规

a1Ex999 @ 2024-10-25 21:50:59

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

by wandereman @ 2024-10-25 22:22:29

你要把每种数量都计算出来,否则可能出现在一个密码中只出现了一种或两种,但你的程序不会把它排除掉,样例能过是因为后面两个的长度都大于12.


by wandereman @ 2024-10-25 22:24:44

而你的程序只能保证都是合法的(没有像&*…%这种)


by wandereman @ 2024-10-25 22:29:14

看一下吧```cpp

include <iostream>

using namespace std; string s; int main() { cin>>s; string t=""; for(int i=0;i<s.length();i++) { if (s[i]!=',') { t += s[i]; } else { bool pd=1; int xx=0,dx=0,sz=0,tsfh=0; for(int j=0;j<t.length();j++) { if(t[j]>='a'&&t[j]<='z') { xx=1; } else if(t[j]>='A'&&t[j]<='Z') { dx=1; } else if(t[j]>='0'&&t[j]<='9') { sz=1; } else if (t[j]=='!'||t[j]=='@'||t[j]=='#'||t[j]=='$') { tsfh=1; } else { pd=0; break; } } if(pd&&xx+dx+sz>=2&&tsfh>=1&&tsfh+xx+dx+sz>=6&&tsfh+xx+dx+sz<=12) { cout<<t<<endl; } t=""; } } return 0; }


by wandereman @ 2024-10-25 22:29:36

求关


by wandereman @ 2024-10-25 22:31:34

看一下吧ACcode


by a1Ex999 @ 2024-11-24 15:19:20

@wandereman


|