2次求助!!样例也过得去,去搜题解对了一下几乎一模一样,但是就是不知道错在哪……
查看原帖
2次求助!!样例也过得去,去搜题解对了一下几乎一模一样,但是就是不知道错在哪……
1559473
JmBecca楼主2024/12/8 08:42

错误代码

#include <bits/stdc++.h>
#include <vector>
using namespace std;
string t,m;
int b=0;
bool check(string s){
	bool n1,n2,n3,n4=false;
	int cnt;
	if(s.length()<6 or s.length()>12)return false;
	else{
		for(int j=0;j<m.length();j++){
			if (m[j]>='0' and m[j]<='9')n1=true;
			else if(m[j]>='A' and m[j]<='Z')n2=true;
			else if(m[j]>='a' and m[j]<='z')n3=true;
			else if(m[j]=='!' or m[j]=='@' or m[j]=='#' or m[j]=='$')n4=true;
			else return false;
		}
	}
	if(n1)cnt++;
	if(n2)cnt++;
	if(n3)cnt++;
	if(cnt>=2 and n4)return true;
}
int main(){
	cin>>t;
	vector<string> a;
	for(int i=0;i<t.length();i++){
		if(t[i]==','){
			a.push_back(t.substr(b,i-b));
			b=i+1;
		}
	}
	a.push_back(t.substr(b,t.length()-b));
	for(int i=0;i<a.size();i++){
		m=a[i];
		if(check(m))cout<<m<<endl;
	}
	return 0;
}

改了之后的错误代码

#include <bits/stdc++.h>
using namespace std;
string s;
int main(){
    cin>>s;
    string a[15];
    int n=0;
    for(int i=0;i<s.length();i++){
        if(s[i]!=',')a[n]+=s[i];
        else n++;
    }
    for(int i=0;i<=n;i++){
        int m1,m2,m3,m4,m5=0;
        if(a[i].length()<6 or a[i].length()>12)continue;
        for(int j=0;j<a[i].length();j++){
            if(isupper(a[i][j]))m1=1;
            else if(islower(a[i][j]))m2=1;
            else if(isdigit(a[i][j]))m3=1;
            else if(a[i][j]=='!' or a[i][j]=='@' or a[i][j]=='#' or a[i][j]=='$')m4=1;
            else m5=1;
        }
        if(m5!=0 or m4==0 or (m1==0 and m2==0) or (m1==0 and m3==0) or (m2==0 and m3==0))continue;
        else cout<<a[i]<<endl;
    }
	return 0;
}
2024/12/8 08:42
加载中...