#include <iostream>using namespace std;//set some computed macro typedef char bytes; #define BYTES_LENGTH 255//A byte data size # define Bytes_half_length 4//Half-byte digits//#define RHALF (bytes_length>>bytes_half_length)//Right half for 00001111#define RHALF 15// #define LHALF (Bytes_length<<bytes_half_length)//left half is 11110000#define lhalf 240#define stored_r (b,n) (B= (n| ( b&lhalf))//to deposit N to the right half of B # # stored_l (b,n) (b= ((n<<bytes_half_length) | ( b&rhalf))//Add N to the left half of B # # Get_r (b) (b&rhalf)//Get the right four-bit # # of B get_l (b) ((b&lhalf) >>bytes_ Half_length)//Get the left of B four-bit # define Mov_with 3//The moving width of the chess piece int main () {bytes b=0;for (stored_r (b,1); Get_r (b) <=MOV_WITH*MOV_WITH; Stored_r (B,get_r (b) +1)) {for (stored_l (b,1); get_l (b) <=MOV_WITH*MOV_WITH; Stored_l (b,get_l (b) +1)) {if (Get_r (b)%mov_with!=get_l (b)%mov_with) {Cout<<get_r (b) << ' <<get_l (b ) <<endl;}}} System ("pause"); return 1;}
The beauty of programming--1.2 Chinese chess Generals problem