题目链接:Click
- swap 函数的利用
- 暴力遍历
#include<iostream> #include<string> #include<algorithm> using namespace std; string s; int solve(const string &s, int x,int y){ int res=0; for(auto c:s) if(c-'0'==x){ res++; swap(x,y); } if(x!=y && res%2==1) res--; return res; } void solve(){ string s; cin>>s; int ans=0; for(int x=0;x<10;x++) for(int y=0;y<10;y++){ ans=max(ans,solve(s,x,y)); } cout<<(int)s.size()-ans<<endl; } int main(){ int t; cin>>t; while(t--){ solve(); } }