Advertisement
Guest User

Untitled

a guest
Dec 14th, 2019
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.59 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6. int q;
  7. cin >> q;
  8. while (q --> 0) {
  9. int n;
  10. cin >> n;
  11. if (n == 1) {
  12. cout << 1 << '\n';
  13. continue;
  14. }
  15. int ans = 0;
  16. int cur = 0;
  17. for (int i = 1; i < 10; ++i) {
  18. for (int j = 1; j <= ceil(log10(n)); ++j) {
  19. cur += i;
  20. if (cur <= n) {
  21. ++ans;
  22. }
  23. cur *= 10;
  24. }
  25. cur = 0;
  26. }
  27. cout << ans << '\n';
  28. }
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement