统计每种字符类型的数量,大于1可替换为其他所有字符,反之只能替换为同类型字符
#include <iostream>
#include<string>
using namespace std;
int gettype(char c){
if(c>='A'&&c<='Z')return 0;
if(c>='a'&&c<='z')return 1;
if(c>='0'&&c<='9')return 2;
if(c==','||c=='.'||c=='?'||c=='!')return 3;
return -1;
}
int solve(const string&s){
int n=s.size();
int ans=0;
int cnt[4]={0};
for(char c:s)cnt[gettype(c)]++;
ans+=cnt[0]*(cnt[0]>1?65:25);
ans+=cnt[1]*(cnt[1]>1?65:25);
ans+=cnt[2]*(cnt[2]>1?65:9);
ans+=cnt[3]*(cnt[3]>1?65:3);
return ans;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin>>t;
while(t--){
string s;
cin>>s;
cout<<solve(s)<<"\n";
}
return 0;
}

京公网安备 11010502036488号