📄 test.c
字号:
/**********************************************************/
/* 本程序在Turbo C或Borland C下编译通过 */
/* */
/* 源代码文件名:TEST.c */
/* */
/* 日期:2003年12月12日 */
/* */
/* 开发人员: Wansong QQ:23156680 */
/* */
/* 版本:version 1.01 */
/**********************************************************/
/***********************************************************/
/* 注:本源程序里还有很多被注释掉的源代码 */
/* */
/* 那些代码是在编制程序时产生的,有的是用来测 */
/* 试数据的代码,有些是源程序里的代码,但是后来 */
/* 由于写出了更好的代码,因而就把它注释掉了,在 */
/* 这里没有把它删掉,主要是想以后能做个参考,以 */
/* 后看到这些代码,就会想起以前学习编程时所发生 */
/* 的一些事,一定又是一段美好的回忆...... ^-^ */
/* */
/* 在这里,我还要感谢我所有的朋友一直以来对我的 */
/* 支持...... */
/***********************************************************/
#include<dos.h>
#include<math.h>
#include<graphics.h>
#include<conio.h>
#include<stdio.h>
#include<alloc.h>
#include<stdlib.h>
FILE *fp1;
FILE *fp2;
int key;
char *hzcode="学校导游咨询系统\n" ;
char *charmaster[3]={"景点简介\n" ,"路线查询\n" ,"退出程序\n"};
/*char *charresult="总共距离为\n";
char *charresult1="米。\n"*/
char *charCheck3[2]={"重新查询\n" ,"返回\n" };
char *charcd[24]={ "大校门\n" ,"体育场\n" ,"音乐学院\n" ,"美术学院\n" ,
"体育馆\n" ,"东方红\n" ,"田家炳\n" ,"图书馆\n" ,
"医院\n" ,"西师街\n" ,"杏园\n" ,"出版社\n" ,
"八教\n" ,"七教\n" ,"李园\n" ,"物理大楼\n" ,
"化工学院\n" ,"一教\n" ,"三教\n" ,"荟文楼\n" ,
"桃园\n" ,"生科院\n" ,"五一所\n" ,"培训学院\n"
};
#define MAX 24
#define up 5000
int cost[MAX][MAX];
int dist[MAX];
int M,N; /*顶点数和边数*/
int v0;
int v1;
int path[MAX];
int count;
int *d;
/*struct
{
int num;
int pnode[MAX];
}path[MAX];*/
void CreatGraph()
{
int i=0,j=0,k;
int vi=0,vj=0,w=0;
fp2=fopen("Graph","r");
if(!fp2){closegraph();printf("Open Graph file error.");exit(0);}
fscanf(fp2,"%d %d",&M,&N);
for(i=0;i<M;++i)
for(j=0;j<M;++j)
{
cost[i][j]=up;
if(i==j) cost[i][j]=0;
}
for(k=0;k<N;++k)
{
fscanf(fp2," %d %d %d",&vi,&vj,&w);
i=vi;
j=vj;
cost[j][i]=cost[i][j]=w;
}
}/*end of function*/
/*int shortdjs()
{
int s[MAX];
int mindis,dis,i,j,u;
for(i=0;i<M;i++)
{
dist[i]=cost[v0][i];
path[i].pnode[0]=v0;
path[i].num=0;
s[i]=0;
}
s[v0]=1;
for(i=1;i<M;i++)
{
mindis=up;
u=0;
for(j=0;j<M;j++)
if(s[j]==0 && dist[j]<=mindis)
{
u=j;
mindis=dist[j];
};
s[u]=1;
for(j=0;j<M;j++)
if(s[j]==0)
{
dis=dist[u]+cost[u][j];
if(dist[j]>dis)
{
dist[j]=dis;
path[j].num++;
path[j].pnode[path[j].num]=u;
}
};
path[i].num++;
path[i].pnode[path[i].num]=i;
}
for(i=0;i<M;i++)
{
printf("%d ",dist[i]);
}
for(i=0;i<M;i++)
{
printf("%d ",path[v1].pnode[i]);
}
getchar();
return path[v1].num;
}*//*最短长度dist[v1],路径for(j=0;j<path[v1].num;j++){path[v1].pnode[j];patho[v1].pnode[path[v1].num]*/
void shortdjs()
{
int i, j, *mark, *pathd, *pathbk;
int w,minc;
int from, to;
int t;
/*path=(int *)malloc(MAX*sizeof(int));*/
d=(int *)malloc(MAX*sizeof(int));
mark=(int *)malloc(MAX*sizeof(int));
pathd=(int *)malloc(MAX*sizeof(int));
pathbk=(int *)malloc(MAX*sizeof(int));
for (i=0; i<MAX; i++) mark[i]=0;
for (i=0; i<MAX; i++) pathd[i]=0;
for (i=0; i<MAX; i++)
{
d[i]=cost[v0][i];
pathd[i]=v0;
}
mark[v0]=1; pathd[v0]=0; d[v0]=0;
for(i=1; i<MAX; i++)
{
minc = up;
w = 0;
for( j = 0; j <MAX; j++ )
if( ( mark[j]==0 ) && ( minc >= d[j] ) )
{ minc=d[j]; w=j; }
mark[w]=1;
for(j=0; j<MAX; j++)
if( (mark[j]==0) && ( cost[w][j] != up ) && ( d[j] > d[w]+cost[w][j] ) )
{
d[j]=d[w]+cost[w][j];
pathd[j]=w;
}
}
from=v0; to=v1;
for(i=0;i<MAX;i++)
path[i]=pathbk[i]=-1;
j=0;
if(d[v1]!=up)
{
while(from!=to)
{
pathbk[j]=pathd[to];
to=pathd[to];
j++;
}
}
j=0;
for(i=MAX-1;i>=0;i--)
if(pathbk[i]!=-1)
{
path[j]=pathbk[i];
j++;
}
path[j]=v1;
count=j+1;
/*w=d[t];
printf("\n%d\n",w);*/
/*for(i=0;i<count;i++)
{ printf("%d ",path[i]); }
printf("\n");
printf("%d ",d[v1]) ;
getchar();*/
/*return d[t];*/
}
/*==============================================================================*/
/*函数声明======================================================================*/
/*==============================================================================*/
void Head(void);
int Master(void);
int Check1(void);
int Info(void);
int Check2(void);
int Check3(void);
word(int *hzcode,int xfd,int yfd,int xjiange,int color,int x,int y);
void Clear2(void);
void Clear1(void);
/*==============================================================================*/
/*MAIN==========================================================================*/
/*==============================================================================*/
main()
{
int dv=VGA,mode=VGAHI;
fp1=fopen("hzk16","rb");
if(!fp1){closegraph();printf("Open hzk16 file error.");exit(0);}
CreatGraph();
initgraph(&dv,&mode,"");
Head();
Master();
closegraph();
fclose(fp1);
fclose(fp2);
}
/*=================================================================================*/
/*界面相关函数=====================================================================*/
/*=================================================================================*/
void Head()
{
unsigned long count=0;
register int x,y;
setbkcolor(0);
setcolor(YELLOW);
cleardevice();
setfillstyle(0,0);
floodfill(1,1,0);
for(x=2,y=2;x<310;x+=4,y+=2)
{
line(320-x,240,320,240-y);
line(320,240-y,320+x,240);
line(320+x,240,320,240+y);
line(320,240+y,320-x,240);
delay(20000);
}
x=0;
while(1)
{
if(kbhit())
{
key=getch();
if(key==13||key==32) break;
}
word(hzcode,3,3,1,x,120,210);
if(x++>16)x=0;
count++;
if(count >60L) break;
}
}
int Master()
{
register int i;
int x,oldx;
Clear1();
setfillstyle(2,12);
bar(0,0,16,479);bar(0,0,639,12);bar(623,0,639,479);bar(0,460,639,479);
for(i=0;i<3;i++)
{
setfillstyle(0,7);
fillellipse(150+i*180,250,80,80);
setfillstyle(1,7);
fillellipse(140+i*180,240,80,80);
}
for(i=0;i<3;i++)
word(charmaster[i],1,1,1,9,110+i*180,235);
x=0;
oldx=1;
while(1)
{
if(oldx!=x)
{
oldx=x;
setfillstyle(1,12);
floodfill(120+x*180,250,2);
word(charmaster[x],1,1,1,YELLOW,110+x*180,235);
}
if(kbhit())
{
key=getch();
switch(key)
{
case 75: /*LEFT*/
setfillstyle(1,7);
floodfill(120+x*180,250,2);
word(charmaster[x],1,1,1,9,110+x*180,235);
x--;if(x<0) x=2;break;
case 77: /*RIGHT*/
setfillstyle(1,7);
floodfill(120+x*180,250,2);
word(charmaster[x],1,1,1,9,110+x*180,235);
x++;if(x>2) x=0;break;
case 13:
switch(x)
{
case 0:Info();break;
case 1:Check1();break;
case 2:Clear2();closegraph();exit(1);break;
} break;
}/*switch*/
}/*endif*/ /****end keybord ctrl ****/
}/*while*/
}
int Info()
{
register int i,j;
int x,y,oldx,oldy;
unsigned long int count=0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -