a53

UnuDoi

a53
Feb 18th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. char invert(char digit)
  5. {
  6. if(digit=='1')
  7. return '2';
  8. else
  9. return '1';
  10. }
  11.  
  12. char _getDigit(int index,int k,string base)
  13. {
  14. if(k==1)
  15. return base[index-1];
  16. const int subSequenceLength=pow(4.0,k-1);
  17. int repetition=index/subSequenceLength ;
  18. int innerI;
  19. if(index%subSequenceLength==0)
  20. innerI=4;
  21. else
  22. {
  23. innerI=index%subSequenceLength;
  24. ++repetition;
  25. }
  26. char result=_getDigit(innerI,k-1,base);
  27. if(repetition==2||repetition==3)
  28. return invert(result);
  29. return result;
  30. }
  31.  
  32. char getDigit(int index,string base)
  33. {
  34. int k=1;
  35. for(int i=4;i<index;++k,i*=4)
  36. ;
  37. return _getDigit(index,k,base);
  38. }
  39.  
  40. int main()
  41. {
  42. int digitIndex;
  43. cin>>digitIndex;
  44. cout<<getDigit(digitIndex,"1221")<<'\n';
  45. return 0;
  46. }
Add Comment
Please, Sign In to add comment