G
GuangQingYang
Unregistered / Unconfirmed
GUEST, unregistred user!
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <memory.h>
#define DIRECTIONERROR -1
#define ROWERROR -2
#define COLERROR -3
char chessboard[9][10];
char getnext(char pos,char direction)
{
//direction的各值代表的意思如下:
//□⑦□⑤□
//⑥□□□④
//□□马□□
//②□□□○
//□③□①□
//马:表示马当前的位置
char x,y,signx=1,signy=1,dx=1;
x= pos/10;
y= pos%10;
if ((direction<0) || (direction>7)) return DIRECTIONERROR;
if (4==(direction&4)) signx=-1;
if (2==(direction&2)) signy=-1;
if (1==(direction&1)) dx=2;
(1==signx)?x+=dx:x-=dx;
(1==signy)?y=y+3-dx:y=y+dx-3;
if ((x<0) || (x>89)) return ROWERROR;
if ((y<0) || (y>89)) return COLERROR;
return x*10+y;
}
void output(char aa[9][10],char *filename)
{
FILE *f;
char vi,vj,v;
f=fopen(filename,"ab+");
fseek(f,0,SEEK_END);
char str[4];
memset(str,0,3);
str[0]=0x20;
for (vi=0;vi<9;vi++)
{
for (vj=0;vj<10;vj++)
{
v=aa[vi][vj];
itoa(v,str+1,10);
if ((v>=0) && (v<10))
{
str[2]=str[1];str[1]=0x20;
}
fwrite(str,1,strlen(str),f);
}
fputc(0x0d,f);
fputc(0x0a,f);
}
fputc(0x0d,f);
fputc(0x0a,f);
fputc(0x0d,f);
fputc(0x0a,f);
fclose(f);
}
void tm(char bb[9][10],char pos,char direction,char deep)
{
char nextpos;
char aa[9][10];
memcpy(aa,bb,90);
if ((pos>0) && (pos<90) && (0==aa[pos/10][pos%10]))
{
aa[pos/10][pos%10]=deep;
nextpos=getnext(pos,direction);
if ((nextpos>0) && (nextpos<90) && (0==aa[nextpos/10][nextpos%10]))
{
for (char i=0;i<8;i++)
tm(aa,nextpos,i,deep+1);
}
else
{
if (deep=90)
{
output(aa,"yy.txt");
}
}
}
}
void tmroot(char aa[9][10],char pos)
{
for (char i=0;i<8;i++)
tm(aa,pos,i,1);
}
void main(char argn,char * argv[])
{
memset(chessboard,0,90);
char mypos;
for (mypos=0;mypos<90;mypos++)
{
tmroot(chessboard,mypos);
}
}
#include <stdio.h>
#include <string.h>
#include <memory.h>
#define DIRECTIONERROR -1
#define ROWERROR -2
#define COLERROR -3
char chessboard[9][10];
char getnext(char pos,char direction)
{
//direction的各值代表的意思如下:
//□⑦□⑤□
//⑥□□□④
//□□马□□
//②□□□○
//□③□①□
//马:表示马当前的位置
char x,y,signx=1,signy=1,dx=1;
x= pos/10;
y= pos%10;
if ((direction<0) || (direction>7)) return DIRECTIONERROR;
if (4==(direction&4)) signx=-1;
if (2==(direction&2)) signy=-1;
if (1==(direction&1)) dx=2;
(1==signx)?x+=dx:x-=dx;
(1==signy)?y=y+3-dx:y=y+dx-3;
if ((x<0) || (x>89)) return ROWERROR;
if ((y<0) || (y>89)) return COLERROR;
return x*10+y;
}
void output(char aa[9][10],char *filename)
{
FILE *f;
char vi,vj,v;
f=fopen(filename,"ab+");
fseek(f,0,SEEK_END);
char str[4];
memset(str,0,3);
str[0]=0x20;
for (vi=0;vi<9;vi++)
{
for (vj=0;vj<10;vj++)
{
v=aa[vi][vj];
itoa(v,str+1,10);
if ((v>=0) && (v<10))
{
str[2]=str[1];str[1]=0x20;
}
fwrite(str,1,strlen(str),f);
}
fputc(0x0d,f);
fputc(0x0a,f);
}
fputc(0x0d,f);
fputc(0x0a,f);
fputc(0x0d,f);
fputc(0x0a,f);
fclose(f);
}
void tm(char bb[9][10],char pos,char direction,char deep)
{
char nextpos;
char aa[9][10];
memcpy(aa,bb,90);
if ((pos>0) && (pos<90) && (0==aa[pos/10][pos%10]))
{
aa[pos/10][pos%10]=deep;
nextpos=getnext(pos,direction);
if ((nextpos>0) && (nextpos<90) && (0==aa[nextpos/10][nextpos%10]))
{
for (char i=0;i<8;i++)
tm(aa,nextpos,i,deep+1);
}
else
{
if (deep=90)
{
output(aa,"yy.txt");
}
}
}
}
void tmroot(char aa[9][10],char pos)
{
for (char i=0;i<8;i++)
tm(aa,pos,i,1);
}
void main(char argn,char * argv[])
{
memset(chessboard,0,90);
char mypos;
for (mypos=0;mypos<90;mypos++)
{
tmroot(chessboard,mypos);
}
}