-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathB.cpp
38 lines (32 loc) · 788 Bytes
/
B.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
#include <bits/stdc++.h>
using namespace std;
#define Fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define endl "\n"
int32_t main(){
Fast;
int t;
cin>>t;
while(t--){
string s;
cin>>s;
int minm = s.length();
int n = s.length();
for(int i = s.length()-1 ; i>=0 ; i--){
if(s[i]=='5'){
for(int j = i-1 ; j>= 0 ;j--){
if(s[j]=='2' || s[j] =='7')
minm = min(minm,n-j-2);
}
}
if(s[i]=='0'){
for(int j=i-1 ; j>= 0 ;j--){
if(s[j]=='0' || s[j]=='5')
minm = min(minm,n-j-2);
}
}
}
cout<<minm<<endl;
}
return 0;
}