思路
可以先统计大写,小写,数字它们的个数。 其中O,o,0单独统计,最后求出答案即可。
详见代码~~
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n;
string s;
signed main(){
cin>>n;
while(n--)
{
int suma=0;//表示字符串中有多少个大写子母
int sumb=0;//表示字符串中有多少个小写子母
int sumc=0;//表示字符串中有多少个数字
int sum=0;//表示字符串中有多少个可用替换的O,o,0
int cntO=0;//表示字符串中有多少个O
int cnto=0;//表示字符串中有多少个o
int cnt0=0;//表示字符串中有多少个0
int ans=0;//统计修改次数
cin>>s;
for(int i=0;i<s.size();i++){
if('A'<=s[i]&&s[i]<='Z'){
//将O单独统计
if(s[i]=='O'){
cntO++;
}
else{
suma++;
}
}
if('a'<=s[i]&&s[i]<='z'){
//将o单独统计
if(s[i]=='o'){
cnto++;
}
else{
sumb++;
}
}
if('0'<=s[i]&&s[i]<='9'){
//将0单独统计
if(s[i]=='0'){
cnt0++;
}
else{
sumc++;
}
}
}
if(suma==0){
if(cntO==0){
ans++;
}
else{
cntO--;
}
}
if(sumb==0){
if(cnto==0){
ans++;
}
else{
cnto--;
}
}
if(sumc==0){
if(cnt0==0){
ans++;
}
else{
cnt0--;
}
}
sum=cntO+cnto+cnt0;
if(sum>=ans){
cout<<ans<<endl;
}
else{
cout<<-1<<endl;
}
}
return 0;
}