Advertisement
Josif_tepe

Untitled

Mar 14th, 2022
746
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.84 KB | None | 0 0
  1. #include <iostream>
  2. #include <cmath>
  3. #include <vector>
  4. #include <queue>
  5. #include <algorithm>
  6. #include <cstring>
  7. #include <fstream>
  8. using namespace std;
  9. string int_to_string(int x) {
  10.     string s = "";
  11.     while(x > 0) {
  12.         s += (x % 10) + '0';
  13.         x /= 10;
  14.     }
  15.     reverse(s.begin(), s.end());
  16.     return s;
  17. }
  18. int main() {
  19.     int n;
  20.     cin >> n;
  21.     string s = "";
  22.     int vkupna_golemina = 0;
  23.     int cnt = 1;
  24.     while(vkupna_golemina < n) {
  25.         s += int_to_string(cnt);
  26.         vkupna_golemina += (int) s.size();
  27.         cnt++;
  28.     }
  29.     int region = vkupna_golemina - (int) s.size();
  30. //    cout << vkupna_golemina <<" " << (int) s.size() << endl;
  31.     int idx = 0;
  32.     while(region < n) {
  33.         region++;
  34.         idx++;
  35.     }
  36.     cout << s[idx - 1] << endl;
  37.     return 0;
  38. }
  39. // 1 12 123 1234 12345
  40.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement