调调代码,我看没有啥问题
查看原帖
调调代码,我看没有啥问题
1049668
mengqinyuan楼主2024/6/30 17:51
#include<iostream>
using namespace std;
string str, password[5000];
int cnt=0, index=0;

bool is_good(string s){
	//检验是否合规
	int number=0, big_letter=0, small_letter=0, special=0;
	if(s.size()<6) return false;
	if(s.size()>12) return false;
	
	for(int i=0; i<=s.size()-1; i++){
		if(s[i]>='0' && s[i]<='9') number++;
		else if(s[i]>='A' && s[i]<='Z') big_letter++;
		else if(s[i]>='a' && s[i]<='z') small_letter++;
		else if(s[i]=='!' || s[i]=='@' || s[i]=='#' || s[i]=='$') special++;
	} 
	
	if(number+big_letter+small_letter+special != s.size()) return false;
	
	if(special<1) return false;
	if(big_letter==0 ) return false;
	if(small_letter==0) return false;
	if(number==0) return false;
	
	return true;
}

int main(){
	cin>>str;
	string s = str + ",  ";
	for(int i=0; i<=s.size()-1; i++){
		if(s[i]==','){
			string pw = s.substr(index, s.find(',', index)-index);
			password[cnt] = pw;
			index = i+1;
			cnt++;
		}
	}
	for(int x=0; x<=cnt; x++){
		if( is_good(password[x]) ) cout<<password[x]<<endl;
	}
	return 0;
}
2024/6/30 17:51
加载中...