Skip to content

Instantly share code, notes, and snippets.

@frzleaf
Last active November 9, 2015 03:54
Show Gist options
  • Save frzleaf/a26b132bf2ad12d6cc61 to your computer and use it in GitHub Desktop.
Save frzleaf/a26b132bf2ad12d6cc61 to your computer and use it in GitHub Desktop.
/*
* bai426.cpp
*
* Created on: Nov 9, 2015
* Author: Le Quang Thanh - 11020287
*/
#include <iostream>
using namespace std;
int main() {
int N;
cout << "N = ";
cin >> N;
int N2 = 1 << N;
bool a[N2][N2];
a[0][0] = 1;
for (int k = 1; k < N2; k <<= 1) {
for (int i = 0; i < k; ++i) {
for (int j = 0; j < k; ++j) {
a[i + k][j] = a[i][j + k] = a[i][j];
a[i + k][j + k] = !a[i][j];
}
}
}
for (int i = 0; i < N2; ++i) {
for (int j = 0; j < N2; ++j) {
if (a[i][j])
cout << "T";
else
cout << "0";
cout << " ";
}
cout << endl;
}
int i, j;
bool b = true;
cout << "i,j = ";
cin >> i;
cin >> j;
N2 >>= 1;
while (N2 > 0) {
if (i >= N2 && j >= N2) {
b = !b;
}
i = i >= N2 ? i - N2 : i;
j = j >= N2 ? j - N2 : j;
N2 >>= 1;
}
cout << "a[" << i << "]" << "[" << j << "] = " << b;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment