编程之美-1.2、中国象棋
2013-03-31 22:35
127 查看
#include "stdafx.h"
#define HALF_BITS_LENGTH 4
#define FULLMASK 255
#define LMASK (FULLMASK<<HALF_BITS_LENGTH)
#define RMASK (FULLMASK>>HALF_BITS_LENGTH)
#define LSET(b,n) (b=((b&RMASK)|(n<<HALF_BITS_LENGTH)))
#define RSET(b,n) (b=((b&LMASK)|n))
#define LGET(b) ((b&LMASK)>>HALF_BITS_LENGTH)
#define RGET(b) (b&RMASK)
#define GRIDW 3
struct
{
unsigned char a:4;
unsigned char b:4;
}i;
int _tmain(int argc, _TCHAR* argv[])
{
//方法一、
unsigned char b;
for(LSET(b,1);LGET(b)<=GRIDW*GRIDW;LSET(b,(LGET(b)+1)))
for(RSET(b,1);RGET(b)<=GRIDW*GRIDW;RSET(b,(RGET(b)+1)))
if(LGET(b)%GRIDW!=RGET(b)%GRIDW)
printf("A = %d, B = %d \n",LGET(b),RGET(b));
}
//方法二、
for(i.a=1;i.a<=9;i.a++)
for(i.b=1;i.b<=9;i.b++)
if(i.a%3!=i.b%3)
printf("A = %d, B = %d\n",i.a,i.b);
return 0;
for(i.a=1;i.a<=9;i.a++)
for(i.b=1;i.b<=9;i.b++)
if(i.a%3!=i.b%3)
printf("A = %d, B = %d\n",i.a,i.b);
return 0;
#define HALF_BITS_LENGTH 4
#define FULLMASK 255
#define LMASK (FULLMASK<<HALF_BITS_LENGTH)
#define RMASK (FULLMASK>>HALF_BITS_LENGTH)
#define LSET(b,n) (b=((b&RMASK)|(n<<HALF_BITS_LENGTH)))
#define RSET(b,n) (b=((b&LMASK)|n))
#define LGET(b) ((b&LMASK)>>HALF_BITS_LENGTH)
#define RGET(b) (b&RMASK)
#define GRIDW 3
struct
{
unsigned char a:4;
unsigned char b:4;
}i;
int _tmain(int argc, _TCHAR* argv[])
{
//方法一、
unsigned char b;
for(LSET(b,1);LGET(b)<=GRIDW*GRIDW;LSET(b,(LGET(b)+1)))
for(RSET(b,1);RGET(b)<=GRIDW*GRIDW;RSET(b,(RGET(b)+1)))
if(LGET(b)%GRIDW!=RGET(b)%GRIDW)
printf("A = %d, B = %d \n",LGET(b),RGET(b));
}
//方法二、
for(i.a=1;i.a<=9;i.a++)
for(i.b=1;i.b<=9;i.b++)
if(i.a%3!=i.b%3)
printf("A = %d, B = %d\n",i.a,i.b);
return 0;
for(i.a=1;i.a<=9;i.a++)
for(i.b=1;i.b<=9;i.b++)
if(i.a%3!=i.b%3)
printf("A = %d, B = %d\n",i.a,i.b);
return 0;
相关文章推荐
- 编程之美 1.2 中国象棋将帅问题
- 编程之美 1.2 中国象棋将帅问题
- 编程之美--游戏之乐--1.2中国象棋将帅问题
- 【编程之美】1.2中国象棋的将帅问题
- 编程之美 ---> 1.2中国象棋将帅问题
- [编程之美] PSet1.2 中国象棋将帅问题
- 编程之美_1.2中国象棋将帅问题
- 编程之美 1.2 中国象棋将帅问题
- 编程之美 - 1.2 中国象棋的将帅问题
- 编程之美 1.2 中国象棋将帅问题
- 读书笔记之编程之美 - 1.2 中国象棋将帅问题(更快的算法)
- 编程之美-中国象棋将帅问题方法整理
- 《编程之美》1.2 中国象棋将帅问题 学习笔记
- 编程之美- 中国象棋将帅问题
- [编程之美]中国象棋将帅问题
- 编程之美二 : 中国象棋将帅问题
- 编程之美 中国象棋将帅问题 的再进一步讨论
- 微软编程之美--中国象棋将帅问题
- 《编程之美》 1.2 中国象棋将帅问题
- 编程之美 -- 中国象棋将帅问题