Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define int int64_t
- int getNrDigs(int x) {
- int r = 0;
- while (x) {
- r++;
- x /= 10;
- }
- return r;
- }
- signed main() {
- int n;
- cin >> n;
- int nrDigs = getNrDigs(n);
- int ans = 0;
- ans += (nrDigs - 1) * 9;
- for (int ch = '1'; ch <= '9'; ch++) {
- if (stoll(string(nrDigs, ch)) > n) {
- ans += int(ch - '0') - 1;
- break;
- }
- }
- cout << ans << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement