#includeiostream#includestdio.h#includestring.h#includestdlib.h#includewindows.h#includeconio.h#defineINF32767intvisited[100],password;//password为后台管理的登录密码FILE*fp;charna[100];charstr1[100],str3[100];intN,M;inta[100][100];usingnamespacestd;//景点信息typedefstruct{intnum;charname[100];charintroduction[500];}VertexType;//图结构信息typedefstruct{intedges[100][100];intn,e;VertexTypevex[100];}MGraph;//typedefstructANode{intadjvex;structANode*nextarc;}ArcNode;typedefstructVnode{ArcNode*firstarc;}VNode;typedefVNodeAdjList[100];typedefstruct{AdjListadjlist;intn,e;}ALGraph;MGraphg;//将文本文件打开并输出文件中的内容voidReadData1(MGraph&g){M=N;FILE*fp;inti=0,j;if((fp=fopen(path.txt,r))==NULL){printf(erroropen!);exit(0);}for(i=0;iM;i++){for(j=0;jM;j++){fscanf(fp,%d,&g.edges[i][j]);}}fclose(fp);}voidWriteData1(MGraph&g){FILE*fp;inti=0,j;if((fp=fopen(path.txt,w))==NULL){printf(erroropen!);exit(0);}for(i=0;iN;i++){for(j=0;jN;j++){//printf(%d,g.edges[i][j]);fprintf(fp,%d,g.edges[i][j]);}}printf(\n\n);fclose(fp);}voidReadData(MGraph&g){FILE*fp;inti=0;if((fp=fopen(data.txt,r))==NULL){printf(erroropen!);exit(0);}while(fscanf(fp,%d%s%s,&g.vex[i].num,g.vex[i].name,g.vex[i].introduction)!=EOF){i++;}N=i;fclose(fp);return;}voidWriteData(MGraph&g){FILE*fp;inti=0;if((fp=fopen(data.txt,w))==NULL){printf(erroropen!);exit(0);}for(i=0;iN;i++)fprintf(fp,%d%s%s\n,g.vex[i].num,g.vex[i].name,g.vex[i].introduction);fclose(fp);}//将邻接矩阵改为邻接表voidMatToList(MGraphg,ALGraph*&G){inti,j;ArcNode*p;G=(ALGraph*)malloc(sizeof(ALGraph));for(i=0;ig.n;i++)G-adjlist[i].firstarc=NULL;for(i=0;ig.n;i++)for(j=g.n-1;j=0;j--){if(g.edges[i][j]!=INF){p=(ArcNode*)malloc(sizeof(ArcNode));p-adjvex=j;p-nextarc=G-adjlist[i].firstarc;G-adjlist[i].firstarc=p;}}G-n=g.n;G-e=g.e;}//查找相应景点的介绍voidFindIntroduction(MGraph&g){intd;intx;while(1){printf(请输入要查询的景点的编号:);scanf(%d,&x);if(x=0&&xN){ReadData(g);printf(\n景点的名称:%s\n,g.vex[x].name);printf(景点的简介:);printf(%s\n\n,g.vex[x].introduction);printf(是否继续查询?\n);printf(0.确定1.取消\n);scanf(%d,&d);while(1){if(d==0||d==1)break;else{printf(输入的数据不合理,请重新输入:);scanf(%d,&d);}}if(d==0)continue;elsebreak;}else{printf(此景点不存在!\n请重新输入\n);}}}//输出两个顶点间的最短路径voidDispath(MGraph&g,intA[][100],intpath[][100]){inti,j,k,s,u,v;printf(请输入你所在景点的编号:);scanf(%d,&u);do{if(u=0&&u=N-1)break;else{printf(该景点不存在!\n请重新输入!\n);scanf(%d,&u);}}while(1);printf(请输入你要去景点的编号:);scanf(%d,&v);do{if(v=0&&v=N-1)break;else{printf(该景点不存在!\n请重新输入!\n);scanf(%d,&v);}}while(1);if(u==v){printf(\n您输入的起点与终点相同!\n\n);}elseif(strcmp(g.vex[u].name,无)==0||strcmp(g.vex[v].name,无)==0){printf(废弃景点!\n);}elseif(u=0&&uN&&v=0&&vN){intchoose;printf(请选择您的需求:\n);printf(0.距离最短\n);printf(1.时间最少\n);printf(2.换乘最少\n);scanf(%d,&choose);intapath[100],d;for(i=0;ig.n;i++){for(j=0;jg.n;j++){if(A[i][j]!=INF&&i!=j&&u==i&&v==j){if(choose==0){printf(\n从%s到%s距离最短的路径为:,g.vex[i].name,g.vex[j].name);}if(choose==1){printf(\n从%s到%s时间最少的路径为:,g.vex[i].name,g.vex[j].name);}if(choose==2){printf(\n从%s到%s换乘最少的路径为:,g.vex[i].name,g.vex[j].name);}k=path[i][j];d=0;apath[d]=j;while(k!=-1&&k!=i){d++;apath[d]=k;k=path[i][k];}d++;apath[d]=i;printf(%s,g.vex[apath[d]].name);for(s=d-1;s=0;s--)printf(-%s,g.vex[apath[s]].name);printf(\n);printf(路径长度为:%d米,A[i][j]);printf(\n);}/*else{printf(废弃景点!\n);}*/}}}elseprintf(\n请输入正确的编号!\n\n);}//查找两顶点间的最短路径voidFindMinPath(MGraph&g){intA[100][100],path[100][100];inti,j,k;for(i=0;ig.n;i++){for(j=0;jg.n;j++){A[i][j]=g.edges[i][j];if(i!=j&&g.edges[i][j]INF)path[i][j]=i;elsepath[i][j]=-1;}}for(k=0;kg.n;k++){for(i=0;ig.n;i++){for(j=0;jg.n;j++){if(A[i][j]A[k][j]+A[i][k]){A[i][j]=A[k][j]+A[i][k];path[i][j]=path[k][j];}}}}Dispath(g,A,path);}//查找两顶点间的所有路径voidFindaPath(MGraph&g,ALGraph*G,intu,intv,intpath[],intd){intw,i;ArcNode*p;visited[u]=1;d++;path[d]=u;if(u==v&&d=1){printf();for(i=0;id;i++)printf(%s-,g.vex[path[i]].name);printf(%s,g.vex[path[d]].name);printf(\n);}p=G-adjlist[u].firstarc;while(p!=NULL){w=p-adjvex;if(visited[w]==0)FindaPath(g,G,w,v,path,d);p=p-nextarc;}visited[u]=0;}//删除景点简介信息voiddelete_str(charstr1[],charstr2[],intlen,charstr3[]){intnum=0,k=0,i=0,j=0;//num用来记录子串的个数k用来记录子串的位置char*p=str2;//使用p还原str到初始位置while(str1[i]!='\0'){if(str1[i]!=str2[j]){str3[k++]=str1[i++];//当str1中的字符与str的首字符不相同时}else{char*temp=str2;for(;(str1[i]==str2[j])&&str2[j]!='\0';j++){i++;}if(j==len){num++;//出现重复子串,num加一}else{//主字符串中存在和子串前几个字符相同的一段字符//退出循环并将这段字符写进新的字符数组中for(intm=0;mj;m++){str3[k++]=temp[m];}}str2=p;j=0;}}}//密码输入函数intinputpassword(){chara[10];intpass=0;inti;while(1){for(i=0;i6;i++){a[i]=getch();putchar('*');if(a[i]='0'&&a[i]='9')pass=pass*10+a[i]-'0';elseif(a[i]=='\b')//当遇到退格键不做处理{printf(\b\b);i--;}else{pass=0;break;//退出for循环后,再次接受}}fflush(stdin);//清除键盘缓存区中已经有的输入printf(\n);if(pass==0)//此条件成立可能由两种情况引起:输入了非数字字符被直接重置为0,或6位全0后正常退出for循环{printf(密码要求全为数字,且不能全0!\n);printf(请重新输入密码:);}elsebreak;}returnpass;}//在图中增加一个景点voidadd_point(MGraph&g){inti,d;N++;g.vex[N-1].num=N-1;//printf(%d\n,N);printf(请输入要增加景点的名称:);scanf(%s,g.vex[N-1].name);while(1){for(i=0;iN-1;i++){if(strcmp(g.vex[i].name,g.vex[N-1].name)