-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathb.cpp
More file actions
61 lines (55 loc) · 1.47 KB
/
Copy pathb.cpp
File metadata and controls
61 lines (55 loc) · 1.47 KB
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
61
#include <bits/stdc++.h>
using namespace std;
int t, in2, in5, in0, in7, temp, af0, af5, res;
string n;
//unsigned long long n;
int main(){
ios_base :: sync_with_stdio(0);
cin.tie(0); cout.tie(0);
cin >> t;
while(t--){
in0 = af0 = in5 = af5 = 0;
cin >> n;
int cnt = 1;
int len = n.size();
// cout << len;
for (int i = len -1; i>=0; --i){
if (in0 == 0){
if (n[i] == '0'){
in0 = i + 1;
// cerr << "in0" << in0 << endl;
}
} else{
if (n[i] == '0' || n[i] == '5'){
af0 = i + 1;
//cerr << "af0" << af0 << endl;
break;
}
}
}
for (int i = len -1; i>=0; --i){
if (in5 == 0){
if (n[i] == '5'){
in5 = i + 1;
//cerr << "in5" << in5 << endl;
}
} else{
if (n[i] == '2' || n[i] == '7'){
af5 = i + 1;
//cerr << "af5" << af5 << endl;
break;
}
}
}
res = 100;
//cout << len << ' ' << af0 << ' ' << af5;
if (af0 > 0){
res = min(res, len - af0 - 1);
}
if (af5 > 0){
res = min(res, len - af5 - 1);
}
cout << res << '\n';
}
return 0;
}