Advertisement
updown

Untitled

Feb 23rd, 2023
730
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.55 KB | None | 0 0
  1. #include <iostream>
  2. #include <fstream>
  3. using namespace std;
  4.  
  5. string st;
  6. long long ind;
  7.  
  8. char thru(long long ind) {
  9.     //change to c++ method
  10.     if(ind < st.size()){
  11.       return st[ind];
  12.     }
  13.     int leng = st.size();
  14.     while(2*leng <= ind){
  15.       leng *= 2;
  16.     }
  17.     if (leng == ind){
  18.       return thru(leng-1);
  19.     }
  20.     return thru(ind - leng - 1);
  21. }
  22.  
  23.  
  24. int main() {
  25.     ifstream cin("cowcode.in");
  26.     ofstream cout("cowcode.out");
  27.  
  28.   cin >> st >> ind;
  29.  
  30.   // call fucntion
  31.   char ne = thru(ind-1);
  32.  
  33.   cout << ne << endl;
  34.  
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement