| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 490 人关注过本帖
标题:有个程序亟待改错
只看楼主 加入收藏
知为
Rank: 1
等 级:新手上路
帖 子:112
专家分:0
注 册:2005-10-21
收藏
 问题点数:0 回复次数:4 
有个程序亟待改错

// 这是使用应用程序向导生成的 VC++
// 应用程序项目的主项目文件。

#include "stdafx.h"

#using <mscorlib.dll>

using namespace System;

#include<string.h>
#include<ctype.h>
#include<malloc.h>
#include<limits.h>
#include<stdio.h>
#include<stdlib.h>
#include<io.h>
#include<math.h>
#include<process.h>
#define TRUE 1
#define FALSE 0
#define OK 1
#define ERROR 0
#define INFEASIBLE -1
#define STACK_INIT_SIZE 1000
#define STACK_INCREMENT 20
typedef int Status;
typedef struct
{int x; /* 行值 */
int y; /* 列值 */
}PosType;
PosType start;
typedef struct
{PosType seat;
int di;
}SElemType;
typedef struct SqStack
{
SElemType *base;
SElemType *top;
int stacksize;
}SqStack;
int curstep=1;
int chess[12][12];
void InitStack(SqStack *S)
{ /* 构造一个空栈S */
(*S).base=(SElemType *)malloc(STACK_INIT_SIZE*sizeof(SElemType));
if(!(*S).base)
exit(OVERFLOW); /* 存储分配失败 */
(*S).top=(*S).base;
(*S).stacksize=STACK_INIT_SIZE;
}
Status StackEmpty(SqStack S)
{ /* 若栈S为空栈,则返回TRUE,否则返回FALSE */
if(S.top==S.base)
return TRUE;
else
return FALSE;
}
void Push(SqStack *S,SElemType e)
{ /* 插入元素e为新的栈顶元素 */
if((*S).top-(*S).base>=(*S).stacksize) /* 栈满,追加存储空间 */
{
(*S).base=(SElemType *)realloc((*S).base,((*S).stacksize+STACK_INCREMENT)*sizeof(SElemType));
if(!(*S).base)
exit(OVERFLOW); /* 存储分配失败 */
(*S).top=(*S).base+(*S).stacksize;
(*S).stacksize+=STACK_INCREMENT;
}
*((*S).top)++=e;
}
Status Pop(SqStack *S,SElemType *e)
{ /* 若栈不空,则删除S的栈顶元素,用e返回其值,并返回OK;否则返回ERROR */
if((*S).top==(*S).base)
return ERROR;
*e=*--(*S).top;
return OK;
}
void Print()
{ int i,j;
for(i=0;i<12;i++)
{
for(j=0;j<12;j++)
printf("%6d",chess[i][j]);
printf("\n");
}printf("\n");
}

void Init(int k)
{int i,j;
for(i=0;i<12;i++)
{chess[0][i]=-1;chess[1][i]=-1; chess[11][i]=-1;chess[10][i]=-1;}
for(i=0;i<12;i++)
{chess[i][0]=-1;chess[i][1]=-1; chess[i][11]=-1;chess[i][10]=-1;}
for(i=2;i<10;i++)
for(j=2;j<10;j++)
chess[i][j]=k;
printf("棋盘结构如下:\n");
Print();
}

void MarkPrint(PosType b)
{
chess[b.x][b.y]=0;
}
Status text()
{ int i,j;
for(i=2;i<10;i++)
{
for(j=2;j<10;j++)
if(chess[i][j]==0) return ERROR;
}
return TRUE;
}
Status Pass(PosType b)
{ if(chess[b.x][b.y]==0)
return OK;
else
return ERROR;
}
void FootPrint(PosType a)
{
chess[a.x][a.y]=curstep;
}
void NextPos(PosType *c,int di)
{
PosType direc[8]={{2,1},{1,2},{2,-1},{1,-2},{-2,-1},{-1,-2},{-2,1},{-1,2}};
(*c).x+=direc[di].x;
(*c).y+=direc[di].y;
}
Status chessPath(PosType start)
{ SqStack S;
PosType curpos; int z;
SElemType e;
InitStack(&S);
curpos=start;
do
{
if(Pass(curpos))
{ FootPrint(curpos);
e.seat=curpos;
e.di=0;
Push(&S,e);
curstep++;Print();scanf("%d",&z);
if(text()) return TRUE;
NextPos(&curpos,e.di);
}
else
{ if(!StackEmpty(S))
{
curstep--; Pop(&S,&e);
while(e.di==7&&!StackEmpty(S))
{if(chess[curpos.x][curpos.y]) MarkPrint(e.seat);

Pop(&S,&e);curstep--;
}
if(e.di<7)
{
e.di++;
Push(&S,e);
curpos=e.seat; curstep++;
NextPos(&curpos,e.di);
}
}
}
}while(!StackEmpty(S));
return FALSE;
}
void main()
{
Init(0);
int i,j;
for(i=2;i<11;i++)
{
for(j=2;j<12;j++)
{ start.x=i;start.y=j;if(chessPath(start)){printf ("answer is\n");Print();}}
}
}

真希望哪个高手给我改改

谢谢了

搜索更多相关主题的帖子: 改错 亟待 亟待 改错 
2005-10-28 20:00
猪也聪明
Rank: 1
等 级:新手上路
帖 子:156
专家分:0
注 册:2005-5-16
收藏
得分:0 
你希望实现什么功能先告诉我

虽然我没有翅膀,可是我希望飞的高点
2005-10-29 21:36
84819986
Rank: 1
等 级:新手上路
帖 子:25
专家分:0
注 册:2005-10-30
收藏
得分:0 
看起来就很难 我是不行的拉  都大三了 还这么菜  晕了
2005-10-30 10:27
知为
Rank: 1
等 级:新手上路
帖 子:112
专家分:0
注 册:2005-10-21
收藏
得分:0 


还是好人多啊,谢谢你给我回帖了

骑士(只能跳“日”字格)走满8*8棋盘,而且没有重复


2005-10-31 17:49
知为
Rank: 1
等 级:新手上路
帖 子:112
专家分:0
注 册:2005-10-21
收藏
得分:0 
就是和象棋中的马一样

2005-10-31 17:49
快速回复:有个程序亟待改错
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.015646 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved