-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path88328880.cpp
60 lines (60 loc) · 905 Bytes
/
88328880.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
#include<bits/stdc++.h>
using namespace std;
int solve(string str,char a,char b)
{
int n=str.size();
int del=0;
int index=0;
int turn=0;// mean a
while(index<n)
{
if(turn==0)// a
{
if(str[index]!=a)
{
del++;
}
else
{
turn=!turn;
}
}
else// b
{
if(str[index]!=b)
{
del++;
}
else
{
turn=!turn;
}
}
index++;
}
if(turn==1 && a!=b)return del+1;
return del;
}
void func()
{
string str;
cin>>str;
int res=str.size();
string nums="0123456789";
for(int i=0;i<10;i++)
for(int j=0;j<10;j++)
{
int out=solve(str,nums[i],nums[j]);
//cout<<"call by "<<str<<" "<<nums[i]<<" "<<nums[j]<<"-->"<<out<<endl;
res=min(res,out);
}
cout<<res<<endl;
}
int main()
{
int t;
cin>>t;
for(int i=0;i<t;i++)
func();
return 0;
}