Untitled
unknown
plain_text
2 years ago
553 B
4
Indexable
#include <iostream> #include <algorithm> #include <vector> #include <string> using namespace std; int perevod_obratno(string o) { string a = o; int j = 0; int tmp = 1; for (int i = 0; i < size(a); i++){ if (a[i] == '1') tmp = 0; else if (a[i] == '0') tmp = 1; j += tmp * pow(2, i); } return j; } int perevod_tuda(int a) { string h = ""; int k = a; while (k != 1){ h += to_string(k % 2); k /= 2; } h += "1"; return perevod_obratno(h); } int main() { int a; cin >> a; cout << perevod_tuda(a); }
Editor is loading...