Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <bitset>
- #include <cmath>
- typedef unsigned char uc;
- const int size_uc = 8 * sizeof(uc);
- using namespace std;
- uc Gray(const uc &n) {
- return (n ^ (n >> 1));
- }
- int main() {
- cout << "n:";
- int n;
- cin >> n;
- for (int i = 0; i < pow(2,n); ++i) {
- uc x = i;
- uc gray_x = Gray(x);
- bitset<8> s = bitset<size_uc>(gray_x);
- string s1;
- for (int j = 0; j < n; ++j) {
- s1+= to_string(s[j]);
- }
- string s2;
- for (int j = 0; j < s1.length(); ++j) {
- s2+= s1[s1.length()-j-1];
- }
- cout << s2 << "\n";
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment