jiangjinke @ 2024-10-19 18:53:36
#include<bits/stdc++.h>
using namespace std;
int main(){
string a;
int t=0,sum=0,x=0,y=0;
cin>>a;
bool b=0;
string q="";
for(int i=0;i<a.size();i++){
if(a[i]!=','){
q=q+a[i];
}
else
{
for(int j=0;j<q.size();j++){
if(q[j]>='A'&&q[j]<='Z'){
x++;
continue;
}else if(q[j]>='a'&&q[j]<='z'){
x++;
continue;
}else if(q[j]>='0'&&q[j]<='9'){
x++;
continue;
}
else if(q[j]=='@'){
y++;
continue;
}else if(q[j]== '!'){
y++;
continue;
}else if(q[j]== '#'){
y++;
continue;
}else if(q[j]=='$'){
y++;
continue;
}else { b=1;}
}
if(b==0&&q.size()>=6&&q.size()<=12&&x>=2&&y>=1){
cout<<q<<"\n";
}
q="";
b=x=y=0;
}
}
return 0;
}
by LLh_kun @ 2024-11-11 20:13:40
@jiangjinke
都放在代码里了,不懂的地方私信我
#include<bits/stdc++.h>
using namespace std;
int main(){
string a;
int t=0,sum=0,x=0,y=0,x1=0,x2=0;//顺便问一句,t有什么用
cin>>a;
bool b=0;
string q="";
for(int i=0;i<a.size();i++){
if(a[i]!=','){
q=q+a[i];
}
else
{
for(int j=0;j<q.size();j++){
if(q[j]>='A'&&q[j]<='Z'){
x=1;//这里是记有多少种,不是有多少个,=1就行了
continue;
}else if(q[j]>='a'&&q[j]<='z'){
x1=1;//有一种可能就是你下面的x>=2可能全是大写或全是数字
continue;
}else if(q[j]>='0'&&q[j]<='9'){
x2=1;//同上
continue;
}
else if(q[j]=='@'){
y++;
continue;
}else if(q[j]== '!'){
y++;
continue;
}else if(q[j]== '#'){
y++;
continue;
}else if(q[j]=='$'){
y++;
continue;
}else {b=1;}
}
sum=x+x1+x2;//统计有多少种
if(b==0&&q.size()>=6&&q.size()<=12&&sum>=2/*种类大于2就行*/&&y>=1){
cout<<q<<"\n";
}
q="";
x1=x2=sum=b=x=y=0;//多了一个sum,x1,x2
}
}
return 0;
}
by LLh_kun @ 2024-11-11 20:15:15
亲测可AC
@jiangjinke
by LLh_kun @ 2024-11-11 20:37:21
连接上个代码
//到这里了,我只能说:这数据太水了!!!
//由于字符串最后是没有“,”的(那个输出答案的判断是假如这个字符是‘,’才会进入)
//所以假设最后一个是合法的,那么他在结尾没有遇到“,”
//以至于即使合法最后一个也不会进入那个判断输出 !!
//所以得在后面再加一个代码
//(这个数据水到不加这段代码也不会错,但实际一些数据是过不去的)
for(int j=0;j<q.size();j++){
if(q[j]>='A'&&q[j]<='Z'){
x=1;
continue;
}else if(q[j]>='a'&&q[j]<='z'){
x1=1;
continue;
}else if(q[j]>='0'&&q[j]<='9'){
x2=1;
continue;
}
else if(q[j]=='@'){
y++;
continue;
}else if(q[j]== '!'){
y++;
continue;
}else if(q[j]== '#'){
y++;
continue;
}else if(q[j]=='$'){
y++;
continue;
}else {b=1;}
}
sum=x+x1+x2;
if(b==0&&q.size()>=6&&q.size()<=12&&sum>=2&&y>=1){
cout<<q<<"\n";
}
再次求关 o(TωT)o