-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1593B.cpp
More file actions
50 lines (37 loc) · 744 Bytes
/
1593B.cpp
File metadata and controls
50 lines (37 loc) · 744 Bytes
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
#include <bits/stdc++.h>
using namespace std;
int min_operations(string n, string possible_value)
{
int operations = 0;
int checker_index = possible_value.size() - 1;
for (int i = n.size() - 1; i >= 0; i--)
{
if (n[i] == possible_value[checker_index])
{
checker_index--;
if (checker_index < 0)
break;
}
else
operations++;
}
if (checker_index >= 0)
operations = INT_MAX;
return operations;
}
int main()
{
long long t;
cin >> t;
while (t--)
{
string n;
cin >> n;
vector<string> possible_values = {"00", "25", "50", "75"};
int ans = INT_MAX;
for (auto possible_value : possible_values)
ans = min(ans, min_operations(n, possible_value));
cout << ans << endl;
}
return 0;
}