#include<stdio.h>
#include<stdlib.h>
#include<malloc.h>
#include<conio.h>
#define MAX 14
#define MOV 100
/*----------首个城市----------*/
typedef struct city /* 城市数据类型 */
{
char code; /* 城市代码 */
}city;
city ks1;
typedef struct traffic /* 交通信息数据类型 */
{char code; /*城市代码 */
int dist; /* 城市间的里程 */
int p1;
int p2;
int p3;
int p4; /* 航班时刻 */
}traffic;
traffic ks2;
typedef struct traf
{int flag;/*标志*/
char code;/*城市*/
char rcode;/*来的城市*/
int gtime;/*出发时间*/
int ttime;/*选择的航班时间*/
int utime;/*消耗时间*/
int udata;/*出发天序数*/
int time[4];/*航班时间*/
int road;
struct traf *next;
}traf;
traf *h[14],*t,*p,*q,*m,*n;
typedef struct st /* 栈结构 */
{char code;
int road;
int ttime;
int gtime;
int utime;
int udata;
}info;
typedef struct stk
{info *s;
int top;
}stk;
/*-输入城市和交通并存放于文件中-*/
inputcall()
{
FILE *fp;
int a,b,i,j;
clrscr();
if((fp=fopen("stu_list","w+"))==NULL){printf("can not open");return 1;}
printf("\nplease input all city number:");
scanf("%d",&a);
fputc(a,fp);
for(j=0;j<a;j++)
{
printf("\nplease input OK %d city:",j+1);
scanf("%s",&ks1.code);
fwrite(&ks1,sizeof(struct city),1,fp);
printf("\nplease input other city number:");
scanf("%d",&b);
fputc(b,fp);
for(i=0;i<b;i++)
{printf("\nplease input other city like (a 1000 11 12 13 14):");
scanf("%s %d %d %d %d %d",&ks2.code,&ks2.dist,&ks2.p1,
&ks2.p2,&ks2.p3,&ks2.p4);
fwrite(&ks2,sizeof(struct traffic),1,fp);
}
clrscr();
}
fclose(fp);
}
/*--------------------------*/
/*-----打开文件构建交通-----*/
usetraffic()
{FILE *fp;
int a,b,i,j;
if((fp=fopen("stu_list","rb"))==NULL){printf("can not open");return 1;}
a=fgetc(fp);
for(j=0;j<a;j++)
{
fread(&ks1,sizeof(struct city),1,fp);
m=(traf *)malloc(sizeof(traf));
h[j]=m;h[j]->code=ks1.code;h[j]->rcode=' ';h[j]->flag=0;
h[j]->gtime=0;h[j]->utime=100;
b=fgetc(fp);
for(i=0;i<b;i++)
{
fread(&ks2,sizeof(struct traffic),1,fp);
n=(traf*)malloc(sizeof(traf));
n->code=ks2.code;n->road=ks2.dist;n->time[0]=ks2.p1;
n->time[1]=ks2.p2;n->time[2]=ks2.p3;n->time[3]=ks2.p4;
m->next=n;m=m->next;
}
m->next=NULL;
}
fclose(fp);
}
/*--------------------------*/
/*------查找出发的城市------*/
search(char city,int time)
{
int i;
for(i=0;i<=13;i++)
{
if(h[i]->code==city)
{
h[i]->flag=1;h[i]->udata=0;
h[i]->gtime=time;h[i]->utime=0;
break;
}/*出发的城市初始化*/
}
return 1;
}
/*--------------------------*/
/*------查找经过的城市------*/
searchtraf()
{int i,z=0;
for(i=0;i<=13;i++)
{
if(h[i]->flag==1){p=t=h[i];h[i]->flag=0;z=1;break;}
}
return(z);
}
/*--------------------------*/
/*----------q指向-----------*/
pcode()
{
int i;
for(i=0;i<=13;i++)
{
if(h[i]->code==p->next->code)
{
q=h[i];
break;
}
}
return 1;
}
/*--------------------------*/
/*-----计算所需要的时间-----*/
sohutime()
{
int i,y=0;
int wtime,rtime,ttime,udata,thistime,thisutime,thisdata;
for(i=0;i<=3;i++)
{
if(p->next->time[i]>=t->gtime)
{
wtime=p->next->time[i]-t->gtime;
rtime=p->next->road/MOV;udata=t->udata;
ttime=p->next->time[i];y=1;
break;
}
}
if(y==0)
{
wtime=24-t->gtime+p->next->time[0];
ttime=p->next->time[0];
rtime=p->next->road/MOV;
udata=t->udata+1;
}
thistime=ttime+rtime;
if(thistime>=24)
{
udata=udata+1;
thistime=thistime-24;
}
thisutime=t->utime+wtime+rtime;
thisdata=udata;
if(thisutime<q->utime)
{
q->rcode=t->code;
q->utime=thisutime;
q->gtime=thistime;
q->udata=thisdata;
q->ttime=ttime;
q->road=p->next->road;
q->flag=1;
}
return 1;
}
/*--------------------------*/
/*---------输出结果---------*/
infoprint(char gcy,char tcy)
{
stk s1;
int i,j;
char ch;
char str[20];
s1.s=(info*)malloc(sizeof(info));
s1.top=-1;
clrscr();
while(gcy!=tcy)
{
for(i=0;i<=13;i++)
{
if(h[i]->code==tcy)
{
s1.top++;s1.s[s1.top].code=h[i]->code;
s1.s[s1.top].gtime=h[i]->gtime;
s1.s[s1.top].utime=h[i]->utime;
s1.s[s1.top].udata=h[i]->udata;
s1.s[s1.top].ttime=h[i]->ttime;
s1.s[s1.top].road=h[i]->road;
tcy=h[i]->rcode;
break;
}
}
}
for(i=0;i<=13;i++)
{
if(h[i]->code==gcy)
{
s1.top++;
s1.s[s1.top].code=h[i]->code;
s1.s[s1.top].gtime=h[i]->gtime;
s1.s[s1.top].utime=h[i]->utime;
s1.s[s1.top].udata=h[i]->udata;
s1.s[s1.top].ttime=h[i]->ttime;
s1.s[s1.top].road=h[i]->road;
break;
}
}
j=s1.top;
for(i=s1.top;i>=0;i--)
{
ch=s1.s[i].code;
switch(ch)
{
case 'a': sprintf(str,"bei jing");break;
case 'b': sprintf(str,"shang hai");break;
case 'c': sprintf(str,"chong qing");break;
case 'd': sprintf(str,"cheng du");break;
case 'e': sprintf(str,"guang zhou");break;
case 'f': sprintf(str,"hang zhou");break;
case 'g': sprintf(str,"ha er bing");break;
case 'h': sprintf(str,"kun ming");break;
case 'i': sprintf(str,"lan zhou");break;
case 'j': sprintf(str,"nan jing");break;
case 'k': sprintf(str,"shen yang");break;
case 'l': sprintf(str,"la sha");break;
case 'm': sprintf(str,"wu lu mu qi");break;
case 'n': sprintf(str,"wu han");break;
case 'o': sprintf(str,"xi an");break;
}
if(i==j)printf("\ntime:<%d> from <%s> go ",s1.s[i].gtime,str);
else printf("\nnumber:<%d> day on time:<%d> plane to <%s> for <%d>M time:%d in it",s1.s[i].udata+1,s1.s[i].ttime,str,s1.s[i].road,s1.s[i].gtime);
}
printf("\nall use <%d> time",s1.s[0].utime);
printf("\n....Press any key to exit...");
getch();
return 1;
}
/*--------------------------*/
/*---------交通连接---------*/
chickport()
{
int a;
char gcity,tcity;
int gtime;
clrscr();/*清屏*/
usetraffic();/*调用文件操作函数*/
printf("\n....please input go city....:");
gcity=getche();
getch();
printf("\n....please input to city....:");
tcity=getche();
getch();
printf("\n....please input go time....:");
scanf("%d",>ime);
search(gcity,gtime);/*调用函数查找出发城市的位置*/
while(searchtraf()==1)/*调用函数检验经过的城市*/
{
while(p->next)
{
pcode();
sohutime();/*调用函数进行最短时间的计算*/
p=p->next;
}
}
infoprint(gcity,tcity);/*调用函数输出结果*/
return 1;
}
/*--------------------------*/
/*---------调用菜单---------*/
printfcall()
{
char ch;
clrscr();
printf("\n........please input you edit........");
printf("\n..word:('a':input city or edit city)('other word':traffic) \n");
printf("\n..please input..:");
ch=getche();
getch();
if(ch=='a')inputcall();
chickport();
return 1;
}
/*-------------------------*/
main()
{
printfcall();
return 1;
}
VC++编译结果出错
error C2065: 'clrscr' : undeclared identifier
有人说要包含sysetm.h
但是还报错 没有这个文件
包含了conio.h也不行
大虾来救救我吧