fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. #define int long long
  5. #define yes cout << "YES\n";
  6. #define no cout << "NO\n";
  7.  
  8.  
  9. void FastIO(){
  10. ios_base::sync_with_stdio(false);
  11. cin.tie(nullptr);
  12. cout.tie(nullptr);
  13. }
  14.  
  15. int w(string str, char left, char right){
  16. for(int j = str.size()-1; j >= 0; j--){
  17. if(str[j] == right){
  18. for(int i = j-1; i >= 0; i--){
  19. if(str[i] == left){
  20. return (str.size() - j - 1) + (j - i - 1);
  21. }
  22. }
  23. }
  24. }
  25. return LLONG_MAX;
  26. }
  27.  
  28. void solve(){
  29. int n;
  30. cin >> n;
  31.  
  32. if(n%25 == 0){
  33. cout << 0 << '\n';
  34. return;
  35. }
  36.  
  37. string s = to_string(n);
  38.  
  39. int a = LLONG_MAX;
  40.  
  41. a = min(a, w(s,'2','5'));
  42. a = min(a, w(s,'7','5'));
  43. a = min(a, w(s,'5','0'));
  44. a = min(a, w(s,'0','0'));
  45.  
  46. cout << a << '\n';
  47. }
  48.  
  49.  
  50. signed main(){
  51. FastIO();
  52.  
  53. int t = 1;
  54. cin >> t;
  55.  
  56. while (t--){
  57. solve();
  58. }
  59. return 0;
  60. }
Success #stdin #stdout 0s 5312KB
stdin
5
100
71345
3259
50555
2050047
stdout
0
3
1
3
2