Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <clocale>
- #include <string>
- using namespace std;
- string dvoiczn (unsigned long long x);
- unsigned long long obratno(string str);
- int main()
- {
- setlocale(LC_ALL, "ru");
- unsigned long long n;
- string stroka1, stroka2, stroka3;
- cout << "Введите n ";
- cin >> n;
- unsigned long long int j = 0, i = 1;
- while ( j < n)
- {
- stroka1 = dvoiczn(i);
- stroka2 = dvoiczn(obratno(stroka1));
- stroka3 = stroka2.substr(stroka2.size() - stroka1.size());
- if (stroka3 == stroka1)
- j++;
- i++;
- }
- cout << stroka1<< endl;
- return 0;
- }
- string dvoiczn(unsigned long long x)
- {
- string itog;
- do
- {
- itog = char(int('0') + (x % 2))+itog;
- x /= 2;
- } while (x > 0);
- return itog;
- }
- unsigned long long obratno(string str)
- {
- if (str.size() == 1)
- return str[0] - '0';
- int i = str.size() - 1;
- return obratno(str.substr(0, i))*10 + (str[i]-unsigned long long('0'));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement