Reference: http://www.cnblogs.com/huachiwoo/archive/2011/05/03/2034999.html
Seek Hamming distance: http://www.cnblogs.com/ huachiwoo/archive/2011/05/02/2034158.html
&NBSP ; http://www.cnblogs.com/huachiwoo/archive/2011/05/01/2034155.html
Note the XOR/operator ^
and Right Shift >>
/* Id:wangxin12 prog:hamming lang:c++/#include <iostream> #include <fstream> #include <vector> #i
Nclude <string> using namespace std;
int N, B, D;
vector<int> result;
int power (int index) {if (index = 1) return 2;
Return 2 * Power (INDEX-1);
BOOL Check (int i) {for (int k = 0; k < result.size (); k++) {int dis = 0; int c = i ^ result[k];
XOR/XOR while (c) {dis + c & 0x01;//dis + = C & 0x01;
C >>= 1;
/*//another method C &= (c-1); dis++;
*/} if (Dis < D) return false;
return true;
int main () {//input ifstream fin ("hamming.in");
fin>>n>>b>>d;
Fin.close ();
Result.push_back (0);
Calculate for (int i = 1; I <= power (B)-1; i++) {if (Result.size () < N) {if (check (i)) result.push_back (i);
else break;
}//output ofstream Fout ("Hamming.out"); for (int j = 0; J < Result.size (); j + +) {if (j = = Result.size ()-1) {fout<<result[j]<<endl;
Continue
} if (j% = 9) fout<<result[j]<<endl;
else fout<<result[j]<< "";
} fout.close ();
return 0;
}