蜗蜗高强度密码
整体思路:计数+大模拟
整个题目代码又臭又长
但是基本上写对了。
问题就打一个注释吧
代码如下
#include<bits/stdc++.h>
using namespace std;
//using ll=long long;
//using pii=pair<int,int>;
//using pll=pair<ll,ll>;
#define endl '\n';
void gmin(int &x,int y){x=min(x,y);}
void gmax(int &x,int y){x=max(x,y);}
string pt(int st,bool x){return st==1?x?"Yes":"No":x?"YES":"NO";}
int c[4];
char s[100005];
int f(char ch){
if('0'<=ch&&ch<='9') return 1;
if('a'<=ch&&ch<='z') return 2;
return 3;
}
void solve(){
cin>>s+1;
int l=strlen(s+1);
for(int i=1;i<=l;i++){
c[f(s[i])]++;
}
int cnt=0;
for(int i=1;i<=3;i++) if(!c[i]) cnt++;
if(cnt==0){
cout<<0<<endl;
for(int i=1;i<=l;i++) cout<<s[i];
}if(cnt==1){
cout<<1<<endl;
int b=-1;
for(int i=1;i<=3;i++) if(!c[i]) b=i;
bool ok=1;
for(int i=1;i<=l;i++){
if(c[f(s[i])]>1&&ok){
if(b==1) cout<<0;
if(b==2) cout<<'a';
if(b==3) cout<<'A';
ok=0;
}else{
cout<<s[i];
}
}
}if(cnt==2){
cout<<2<<endl;
int a=-1,b=-1;
for(int i=1;i<=3;i++){//这边是3,我一开始写成了l,导致20分
if(!c[i]){
if(a==-1) a=i;
else b=i;
}
}
if(a==1) cout<<0;
if(a==2) cout<<'a';
if(a==3) cout<<"A";
if(b==1) cout<<0;
if(b==2) cout<<'a';
if(b==3) cout<<'A';
for(int i=3;i<=l;i++) cout<<s[i];
}
cout<<endl;
memset(c,0,sizeof c);
}
int main(){
cin.tie(0)->sync_with_stdio(0);
int t=1;
cin>>t;
while(t--) solve();
}

浙公网安备 33010602011771号