fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. using ll = long long;
  5.  
  6. void solve() {
  7. string x;
  8. cin >> x;
  9. for (int i = 0; i < x.size(); i++) {
  10. if (x[i] == '7') {
  11. cout << 0 << endl;
  12. return;
  13. }
  14. }
  15. ll v = stoll(x);
  16. for (int i = 1; i <= 7; i++) {
  17. v--;
  18. string y = to_string(v);
  19. auto it = find(y.begin(), y.end(), '7');
  20. if (it != y.end()) {
  21. cout << i << endl;
  22. return;
  23. }
  24.  
  25. it = find(y.begin(), y.end(), '7' - i);
  26. if (it != y.end()) {
  27. cout << i << endl;
  28. return;
  29. }
  30.  
  31. }
  32. cout << 7 << endl;
  33. }
  34.  
  35. int main() {
  36. int t;
  37. cin >> t;
  38. while (t--) solve();
  39. }
Success #stdin #stdout 0.01s 5276KB
stdin
16
51
60
61
777
12345689
1000000000
2002
3001
977
989898986
80
800001
96
70
15
90
stdout
3
2
1
0
1
3
5
4
0
7
1
2
7
0
7
3