//online parser:
https://www.bccn.net/run/
to be continued...
程序代码:
#include <stdio.h>
#pragma GCC diagnostic ignored "-Wpointer-to-int-cast"
#define POS 0
#define NEG 1
#define CLK_DIR POS
#define MIN_WIDTH 3
#define USR_WIDTH (MIN_WIDTH + 4)
#define USR_W 1 << USR_WIDTH
#define BASE 0
#define UP BASE - (USR_WIDTH + 1)
#define DN BASE + (USR_WIDTH + 1)
#define LF BASE - 1
#define RT BASE + 1
#define CENTER_POS ((USR_WIDTH * USR_WIDTH) >> 1)
#define MIN_LOOP 9
#define CAST2A(a, v) ((char *)(a))[v]
typedef char(*vp)[32];
typedef char(*vr)[USR_WIDTH];
#define CAST2AP(x, p, v) ((vp)(x))[p][v]
#define CAST2AR(x, p, v) ((vr)(x))[p][v]
int cn_matrix(void *pr)
{
int i, j;
#define LOOP_CNT(_c, _c0) (_c - _c0)
for(i = 0; i < USR_WIDTH; i++) {
for(j = 0; j < USR_WIDTH; j++)
if(CENTER_POS == i * USR_WIDTH + j) {
j = (int)&CAST2AR(pr, i, 0);
i = (int)&CAST2A(pr, CENTER_POS);
printf("loop_cnt = %d\n", i - j);
return LOOP_CNT(i, j);
}
}
}
void re_matrix(void *vr, void *vos, int cnt)
{
int i, j;
enum LOOP_E {INN = 0, OTT};
for(i = 0, j = MIN_LOOP; i < j; i++)
CAST2A(vr, CENTER_POS + CAST2AP(vos, INN, i)) = i + 1;
for(i = 0, j = MIN_LOOP * cnt; i < j; i++)
CAST2A(vr, CENTER_POS + CAST2AP(vos, OTT, i)) = (i + 1) % 10;
}
void pt_matrix(void *pr)
{
int i, j;
for(i = 0; i < USR_WIDTH; i++) {
for(j = 0; j < USR_WIDTH; j++)
printf("%d", CAST2AR(pr, i, j));
#define CRLF puts("")
CRLF;
}
}
int main(int argc, char *argv[])
{
int i, j, cnt;
char r[USR_WIDTH * USR_WIDTH] = {0};
void *pr;
#if CLK_DIR == POS
char pos[][32] = {
{0, RT, DN, DN+LF, DN+LF+LF, LF, UP, UP+RT, UP+RT+RT},
{0, RT, RT+RT, UP+RT+RT+RT, UP+UP+RT+RT+RT+RT, UP+UP+RT+RT+RT,
UP+UP+RT+RT, UP+UP+RT, UP+UP, UP+LF, LF+LF, DN+LF+LF+LF,
DN+DN+LF+LF+LF+LF, DN+DN+LF+LF+LF,DN+DN+LF+LF, DN+DN+LF,
DN+DN, DN+RT}
};
#elif CLK_DIR == NEG
char pos[][32] = {
{0, RT, UP+RT+RT, UP+RT, UP, LF, DN+LF+LF, DN+LF, DN},
{0, RT, RT+RT, DN+RT, DN+DN, DN+DN+LF, DN+DN+LF+LF,
DN+DN+LF+LF+LF, DN+DN+LF+LF+LF+LF, LF+LF+LF, LF+LF, UP+LF,
UP+UP, UP+UP+RT, UP+UP+RT+RT, UP+UP+RT+RT+RT,
UP+UP+RT+RT+RT+RT, UP+RT+RT+RT}
};
#endif
re_matrix(r, pos, cn_matrix(r));
pt_matrix(r);
return 0;
}