-
Notifications
You must be signed in to change notification settings - Fork 31
Expand file tree
/
Copy pathB_Make_it_Divisible_by_25.cpp
More file actions
48 lines (43 loc) · 986 Bytes
/
B_Make_it_Divisible_by_25.cpp
File metadata and controls
48 lines (43 loc) · 986 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
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll t, n;
cin>>t;
while(t--)
{
cin>>n;
string s = to_string(n);
int ans = s.size();
bool flag = false;
int curr = 0;
for(int i=s.size()-1; i>=0; i--)
{
if(!flag && s[i]=='5')
flag=true;
else if(flag && (s[i]=='2'||s[i]=='7'))
{
ans = min(ans, curr);
break;
}
else
curr++;
}
flag = false;
curr = 0;
for(int i=s.size()-1; i>=0; i--)
{
if(!flag && s[i]=='0')
flag=true;
else if(flag && (s[i]=='5'||s[i]=='0'))
{
ans = min(ans, curr);
break;
}
else
curr++;
}
cout<<ans<<"\n";
}
}