QIUZHIYANG @ 2024-08-23 11:01:58
WA了(QAQ)
求调。 ```cpp
using namespace std;
string s;
int cnt,sta=0,en;
bool bhg,a,b,c,t;
int main(){
cin>>s;
for(int i=0;i<s.size();i++){
if(s[i]==','&&!bhg&&cnt>=6&&cnt<=12&&t&&a+b+c>=2){
bhg=0,cnt=0,t=0,a=0,b=0,c=0,en=i-1;
for(int j=sta;j<=en;j++){
cout<<s[j];
}
cout<<endl;
sta=i+1;
}
if(s[i]>='a'&&s[i]<='z'){
cnt++;
a=1;
}else if(s[i]>='A'&&s[i]<='Z'){
cnt++;
b=1;
}else if(s[i]>='0'&&s[i]<='9'){
cnt++;
c=1;
}else if(s[i]=='!'||s[i]=='@'||s[i]=='#'||s[i]=='$'){
cnt++;
t=1;
}else{
if(s[i]!=','){
bhg=1;
}
}
}
return 0;
}
by Letmix @ 2024-08-23 11:06:32
优化:
#include<bits/stdc++.h>
using namespace std;
string s;
int cnt,sta=0,en;
bool bhg,a,b,c,t;
int main(){
cin>>s;
for(int i=0;i<s.size();i++){
if(s[i]==','&&!bhg&&cnt>=6&&cnt<=12&&t&&a+b+c>=2){
bhg=0,cnt=0,t=0,a=0,b=0,c=0,en=i-1;
for(int j=sta;j<=en;j++){ cout<<s[j]; }
cout<<endl; sta=i+1;
}
if(s[i]>='a'&&s[i]<='z'){ cnt++; a=1; }
else if(s[i]>='A'&&s[i]<='Z'){ cnt++; b=1; }
else if(s[i]>='0'&&s[i]<='9'){ cnt++; c=1; }
else if(s[i]=='!'||s[i]=='@'||s[i]=='#'||s[i]=='$'){ cnt++; t=1; }
else{ if(s[i]!=','){ bhg=1; }
}
}
return 0; }