E24chensiyu @ 2024-08-16 09:49:34
#include <bits/stdc++.h>
using namespace std;
char a[101];
int main()
{
int i=1,j=0;
int t1,t2,t3,t4;
t1=t2=t3=t4=0;
while(cin>>a[i])
{
if(a[i]=',')
{
if(j>=6&&j<=12&&t1+t2+t3>=2&&t4==1)
{
for(i=1;i<=j;i++)
{
cout<<a[i];
}
cout<<endl;
}
i=1;
j=0;
}
if(a[i]>='a'&&a[i]<='z')
{
j++;
t1=1;
}
if(a[i]>='A'&&a[i]<='Z')
{
j++;
t2=1;
}
if(a[i]>='0'&&a[i]<='9')
{
j++;
t3=1;
}
if((a[i]=='!')||(a[i]=='@')
||(a[i]=='#')||(a[i]=='$'))
{
j++;
t4=1;
}
}
}
by niuniudundun @ 2024-08-22 09:27:01
@E24chensiyu 建议你把字符串分成多个字符串,在判断一下
by niuniudundun @ 2024-08-22 09:28:59
如果不输出,就是判断写错了
by niuniudundun @ 2024-08-22 09:34:37
#include<iostream>
#include<cstring>
using namespace std;
bool f(char s[],int l){
int ans=0,ANS=0,ans0=0,ans_=0;
if(l<6||l>12) return false;
for(int i=0;i<l;i++){
if(s[i]>='a'&&s[i]<='z') ans=1;
else if(s[i]>='A'&&s[i]<='Z') ANS=1;
else if(s[i]>='0'&&s[i]<='9') ans0=1;
else if(s[i]=='!'||s[i]=='@'||s[i]=='#'||s[i]=='$') ans_=1;
else return false;
}
if(ans+ANS+ans0>=2&&ans_==1) return true;
else return false;
}
char x[102],s[102];
int si=0;
int main(){
cin>>x;
int len=strlen(x);
x[len++]=',';
for(int i=0;i<len;i++){
if(x[i]!=',') s[si++]=x[i];
else{
if(f(s,si)){
for(int i=0;i<si;i++){
cout<<s[i];
s[i]=' ';
}
cout<<endl;
}
si=0;
}
}
return 0;
}
这是我的AC代码