校内模拟赛考的,校内OJ过了CF玄学WA,求调。
#include<bits/stdc++.h>
#define int long long
using namespace std;
// const int maxn=1000010;
int T;
int n;
int ans;
int tot1,tot2;
string s;
int a[10];
bool cmp(int a,int b){return a>b;}
int solve(int x,int y){
int tot1=114,tot2=0;
for(int i=0;i<n;i++){
if(tot1==114&&(s[i]-'0'==x||s[i]-'0'==y)){
tot1=s[i]-'0';tot2++;
continue;
}
else{
if(tot1==x){
if(s[i]-'0'==y){
tot1=y;tot2++;
}
}
else{
if(s[i]-'0'==x){
tot1=x;tot2++;
}
}
}
}
tot2/=2;tot2*=2;
return tot2;
}
signed main(){
cin>>T;
while(T--){
cin>>s;n=s.size();memset(a,0,sizeof(a));ans=0;
for(register int i=0;i<n;++i) a[s[i]-'0']++;
sort(a,a+9,cmp);ans=a[0];
for(register int i=1;i<=9;++i){
for(register int j=0;j<=9;++j){
if(i==j) continue;
else ans=max(ans,solve(i,j));
}
}
ans=n-ans;
cout<<ans<<endl;
}
// system("pause");
}