采用了直接的方式来处理每次输入的字符(.
是0 #
是1)
如0110 = 0*2^3 + 1*2^2 + 1*2^1 + 0*2^0;用一个循环计算并直接输出
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; // 1<<N = 2^N int total = (1<<n) * (1<<n) / 4; for (int i = 0; i < total; ++i){ int num = 0; for (int j = 0; j < 4; ++j){ char a; cin >> a; if (a == '.') num = num * 2 + 0; else num = num * 2 + 1; } cout << num << " "; } return 0; }