Algorithm
Code Examples
#1 Code Example with C++ Programming
Code -
C++ Programming
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define endl '\n'
#define debug(n) cout<<(n)<<endl;
const ll INF = 2e18 + 99;
int totcount(string s, string t) {
int count = 0;
int l = s.length();
while(s.length() > 0 && t.length() > 0) {
if(s.back() == t.back()) {
t.pop_back();
}
else {
count++;
}
s.pop_back();
}
if(t.length() == 0){
return count;
}
return l;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin>>t;
while(t--) {
string s;
cin>>s;
if(s.length() < 2) {
cout << s.length()<<endl;
} else {
cout<<min({totcount(s,"00"),totcount(s,"25"),totcount(s,"50"),totcount(s,"75")})<<endl;
}
}
}
Copy The Code &
Try With Live Editor
Input
5
100
71345
3259
50555
2050047
100
71345
3259
50555
2050047
Output
0
3
1
3
2
3
1
3
2
Demonstration
Codeforcess Solution 1593-B B. Make it Divisible by 25 ,C++, Java, Js and Python ,1593-B,Codeforcess Solution