-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1593B.cpp
47 lines (41 loc) · 998 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
42
43
44
45
46
47
#include <bits/stdc++.h>
using namespace std;
// 00, 25, 50, 75
int solve(string n){
bool cinco = false;
bool cero = false;
int ans00 = 0, ans2575 = 0, ans50 = 0;
for (int j = n.length() - 1; j >= 0; --j){
if (n[j] == '0'){
if (!cero){
cero = true;
++ans2575;
} else return ans00; // FOUND 00
} else if (n[j] == '5'){
if (cero) return ans50;
if (!cinco) cinco = true;
else {
++ans2575;
}
++ans00;
++ans50;
} else if (cinco && (n[j] == '2' || n[j] == '7')){
return ans2575;
} else {
++ans00;
++ans2575;
++ans50;
}
}
return 0;
}
int main(){
int t;
cin >> t;
for (int i = 0; i < t; ++i){
string n;
cin >> n;
cout << solve(n) << "\n";
}
return 0;
}