MichaelMao @ 2024-12-01 15:18:28
#include<bits/stdc++.h>
using namespace std ;
string a[105] ;
int main()
{
string s ;
cin >> s ;
int l = s.size() , last = 0 , c = 0 , cnt = 0 ;
for (int i = 0 ; i < l ; i ++)
{
if(s[i] == ','){
c ++ ;
a[c] = s.substr(last , i - 1) ;
last = i + 1 ;
cnt ++ ;
}
}
for (int i = 1 ; i <= cnt ; i ++)
{
int l1 = a[i].size() ;
bool flag = 1 ;
if(!(l1 >= 6 && l1 <= 12)) flag = 0 ;
int s = 0 , b = 0 , n = 0 , p = 0 ;//分别是小写、大写字母,数字,特殊符号
for(int j = 0 ; j < l1 ; j ++)
{
if(a[i][j] >= 'a' && a[i][j] <= 'z') s = 1 ;
else if(a[i][j] >= 'A' && a[i][j] <= 'Z') b = 1 ;
else if(a[i][j] >= '0' && a[i][j] <= '9') n = 1 ;
else if(a[i][j] == '!' || a[i][j] == '#' || a[i][j] == '@' || a[i][j] == '$') p = 1 ;
else flag = 0 ;
if(s + b + n >= 2 && flag == 1 && p == 1) cout << a[i] << endl ;
}
}
return 0 ;
}
本人无能,做到崩溃了,求大佬指教
by caoyichen1 @ 2024-12-01 16:47:29
#include<bits/stdc++.h>
using namespace std;
bool judge_whether_the_password_is_compliant(string m,int t)
{
if (t<6||t>12)
{
return 0;
}
bool does_the_capital_letter_match=0,do_lowercase_letters_match=0,does_the_figure_match=0,does_the_special_character_match=0;
for (int i=0;m[i]!='\0';i++)
{
if (m[i]>='A'&&m[i]<='Z')
{
does_the_capital_letter_match=1;
}
else if(m[i]>='a'&&m[i]<='z')
{
do_lowercase_letters_match=1;
}
else if(m[i]>='0'&&m[i]<='9')
{
does_the_figure_match=1;
}
else if(m[i]=='!'||m[i]=='@'||m[i]=='#'||m[i]=='$')
{
does_the_special_character_match=1;
}
else
{
return 0;
}
}
if (!does_the_special_character_match||does_the_capital_letter_match+do_lowercase_letters_match+does_the_figure_match<2)
{
return 0;
}
return 1;
}
int main()
{
char n[102],m[102];
int t=0;
cin>>n;
for (int i=0;n[i]!='\0';i++)
{
if (n[i]!=',')
{
m[t]=n[i];
t++;
}
else
{
m[t]='\0';
if (judge_whether_the_password_is_compliant(m,t))
{
cout<<m<<endl;
}
t=0;
}
}
if (t>0)
{
m[t]='\0';
if (judge_whether_the_password_is_compliant(m,t))
{
cout<<m;
}
}
return 0;
}
by guhaoyu_1 @ 2024-12-06 11:22:22
#include<bits/stdc++.h>
using namespace std;
bool isTes(char c){//判断特殊符号是否合法
if(c=='!')return 1;
if(c=='@')return 1;
if(c=='#')return 1;
if(c=='$')return 1;
return 0;
}
bool ok(string s){//判断密码是否合法
if(s.size()<6||s.size()>12)return 0;
bool has0=0,hasa=0,hasA=0,hasT=0;
for(int i=0;i<s.size();i++){
char c=s[i];
if(!(isdigit(c)||islower(c)||isupper(c)||isTes(c)))return 0;
if(isdigit(c))has0=1;
if(islower(c))hasa=1;
if(isupper(c))hasA=1;
if(isTes(c))hasT=1;
}
if(hasT&&(hasa+has0+hasA>=2))return 1;
return 0;
}
int main(){
string s;
cin>>s;
for(int i=0;i<s.size();i++){
if(s[i]==',')s[i]=' ';
}
stringstream ss;
ss<<s;
string w;
while(ss>>w){
if(ok(w))cout<<w<<'\n';
}
return 0;
}
by MichaelMao @ 2024-12-15 13:37:37
@guhaoyu_1@caoyichen1 感谢两位大佬
by caoyichen1 @ 2024-12-15 20:11:48
@MichaelMao
~