SHARE
TWEET

Untitled

a guest Dec 9th, 2019 69 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <clocale>
  3. #include <string>
  4.  
  5. using namespace std;
  6. string dvoiczn (unsigned long long x);
  7. unsigned long long obratno(string str);
  8.  
  9. int main()
  10. {
  11.     setlocale(LC_ALL, "ru");
  12.     unsigned long long  n;
  13.     string stroka1, stroka2, stroka3;
  14.     cout << "Введите  n ";
  15.     cin >> n;
  16.     unsigned long long int j = 0, i = 1;
  17.     while ( j < n)
  18.     {
  19.         stroka1 = dvoiczn(i);
  20.         stroka2 = dvoiczn(obratno(stroka1));
  21.         stroka3 = stroka2.substr(stroka2.size() - stroka1.size());
  22.         if (stroka3 == stroka1)
  23.             j++;
  24.         i++;
  25.        
  26.        
  27.     }
  28.             cout << stroka1<< endl;
  29.        
  30.  
  31.  
  32.     return 0;
  33. }
  34. string dvoiczn(unsigned long long x)
  35. {
  36.     string itog;
  37.     do
  38.     {
  39.     itog = char(int('0') + (x % 2))+itog;
  40.     x /= 2;
  41.     } while (x > 0);
  42.     return itog;
  43. }
  44. unsigned long long obratno(string str)
  45. {
  46.     if (str.size() == 1)
  47.         return str[0] - '0';
  48.     int i = str.size() - 1;
  49.     return obratno(str.substr(0, i))*10 + (str[i]-unsigned long long('0'));
  50. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top