-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy path1593B.cpp
41 lines (38 loc) · 831 Bytes
/
1593B.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
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define debug(n) cout<<(n)<<endl;
const ll INF = 2e18 + 99;
int totcount(string s, string t) {
int count = 0;
int l = s.length();
while(s.length() > 0 && t.length() > 0) {
if(s.back() == t.back()) {
t.pop_back();
}
else {
count++;
}
s.pop_back();
}
if(t.length() == 0){
return count;
}
return l;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while(t--) {
string s;
cin>>s;
if(s.length() < 2) {
cout << s.length()<<endl;
} else {
cout<<min({totcount(s,"00"),totcount(s,"25"),totcount(s,"50"),totcount(s,"75")})<<endl;
}
}
}