全国交通咨询模拟 数据结构 源代码
// 全国交通咨询模拟.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include
#include
#include
#include
#include
using namespace std;
#define INF 9999999 //定义一个最大数定为无穷值
#define MAX 30//最多可以添加15个城市
int addcityflag=0;//标记添加城市的个数
int delcityflag=0;//标记删除城市的个数
int delcity[6];//delcity[0]不用
static int c_number=25;//当前城市个数
typedef int costAdj[MAX+1][MAX+1];//邻接矩阵从1开始记数
//定义该类型
int Path[MAX+1][MAX+1][MAX+1];//三维矩阵用来输出Path[i][i]“二维”中的路径costAdj h_cost,h_time,h_transer,p_cost,p_time,p_transer;//全局矩阵
costAdj COST,ELSE;//乘放不同类型的领接矩阵
string addcity[6];//addcity[0]不用,最多添加5个城市信息
//用来添加城市名称
void set_h_cost(){//构造火车费用的邻接矩阵
for(int i=1;i<=MAX;i++){//矩阵各值置为INF
for(int j=1;j<=MAX;j++){
h_cost[i][j]=INF;
}
}
h_cost[1][2]=h_cost[2][1]=842;//成都-西安
h_cost[1][6]=h_cost[6][1]=967;//成都-贵阳
h_cost[2][3]=h_cost[3][2]=511;//西安-郑州
h_cost[3][10]=h_cost[10][3]=349;//郑州-徐州
h_cost[3][4]=h_cost[4][3]=534;//郑州-武汉
h_cost[4][5]=h_cost[5][4]=409;//武汉-株洲
h_cost[5][8]=h_cost[8][5]=675;//株洲-广州
h_cost[5][6]=h_cost[6][5]=902;//株洲-贵阳
h_cost[6][7]=h_cost[7][6]=607;//贵阳-柳州
h_cost[5][7]=h_cost[7][5]=672;//株洲-柳州
h_cost[9][7]=h_cost[7][9]=255;//柳州-南宁
h_cost[6][11]=h_cost[11][6]=639;
h_cost[1][11]=h_cost[11][1]=1100;
h_cost[8][12]=h_cost[12][8]=140;
h_cost[13][14]=h_cost[14][13]=622;
h_cost[13][15]=h_cost[15][13]=825;
h_cost[10][15]=h_cost[15][10]=651;
h_cost[10][17]=h_cost[17][10]=674;
h_cost[3][16]=h_cost[16][3]=695;
h_cost[16][17]=h_cost[17][16]=137;
h_cost[17][18]=h_cost[18][17]=704;
h_cost[18][19]=h_cost[19][18]=397;
h_cost[18][20]=h_cost[20][18]=305;
h_cost[20][21]=h_cost[21][10]=242;
h_cost[16][23]=h_cost[23][16]=668;
h_cost[2][22]=h_cost[22][2]=676;
h_cost[22][23]=h_cost[23][22]=1145;
h_cost[22][25]=h_cost[25][22]=216;
h_cost[22][24]=h_cost[24][22]=1892;
}
void set_p_cost(){//构造飞机费用的邻接矩阵for(int i=1;i<=MAX;i++){//矩阵各值置为INF for(int j=1;j<=MAX;j++){
p_cost[i][j]=INF;
}
}
p_cost[1][2]=p_cost[2][1]=842*2;//成都-西安
p_cost[1][6]=p_cost[6][1]=967*2;//成都-贵阳
p_cost[2][3]=p_cost[3][2]=511*2;//西安-郑州
p_cost[3][10]=p_cost[10][3]=349*2;//郑州-徐州p_cost[3][4]=p_cost[4][3]=534*2;//郑州-武汉
p_cost[4][5]=p_cost[5][4]=409*2;//武汉-株洲
p_cost[5][8]=p_cost[8][5]=675*2;//株洲-广州
p_cost[5][6]=p_cost[6][5]=902*2;//株洲-贵阳
p_cost[6][7]=p_cost[7][6]=607*2;//贵阳-柳州
p_cost[5][7]=p_cost[7][5]=672*2;//株洲-柳州
p_cost[9][7]=p_cost[7][9]=255*2;//柳州-南宁
p_cost[6][11]=p_cost[11][6]=639*2;
p_cost[1][11]=p_cost[11][1]=1100*2;
p_cost[5][13]=p_cost[13][5]=367*2;
p_cost[8][12]=p_cost[12][8]=140*2;
p_cost[13][14]=p_cost[14][13]=622*2;
p_cost[13][15]=p_cost[15][13]=825*2;
p_cost[10][15]=p_cost[15][10]=651*2;
p_cost[10][17]=p_cost[17][10]=674*2;
p_cost[16][17]=p_cost[17][16]=137*2;
p_cost[17][18]=p_cost[18][17]=704*2;
p_cost[18][19]=p_cost[19][18]=397*2;
p_cost[18][20]=p_cost[20][18]=305*2;
p_cost[20][21]=p_cost[21][10]=242*2;
p_cost[16][23]=p_cost[23][16]=668*2;
p_cost[2][22]=p_cost[22][2]=676*2;
p_cost[22][23]=p_cost[23][22]=1145*2;
p_cost[22][25]=p_cost[25][22]=216*2;
p_cost[22][24]=p_cost[24][22]=1892*2;
}
void set_h_time(){//构造火车费用的邻接矩阵for(int i=1;i<=MAX;i++){//矩阵各值置为INF for(int j=1;j<=MAX;j++){
h_time[i][j]=INF;
}
}
h_time[1][2]=h_time [2][1]=8;//成都-西安
h_time[1][6]=h_time[6][1]=9;//成都-贵阳
h_time[2][3]=h_time[3][2]=5;//西安-郑州
h_time[3][10]=h_time[10][3]=3;//郑州-徐州
h_time[3][4]=h_time[4][3]=5;//郑州-武汉
h_time[4][5]=h_time[5][4]=4;//武汉-株洲
h_time[5][8]=h_time[8][5]=6;//株洲-广州
h_time[5][6]=h_time[6][5]=9;//株洲-贵阳
h_time[6][7]=h_time[7][6]=6;//贵阳-柳州
h_time[5][7]=h_time[7][5]=6;//株洲-柳州
h_time[9][7]=h_time[7][9]=2;//柳州-南宁
h_time[6][11]=h_time[11][6]=6;
h_time[1][11]=h_time[11][1]=11;
h_time[5][13]=h_time[13][5]=3;
h_time[8][12]=h_time[12][8]=1;
h_time[13][14]=h_time[14][13]=6;
h_time[13][15]=h_time[15][13]=8;
h_time[10][15]=h_time[15][10]=6;
h_time[10][17]=h_time[17][10]=6;
h_time[3][16]=h_time[16][3]=6;
h_time[16][17]=h_time[17][16]=1;
h_time[17][18]=h_time[18][17]=7;
h_time[18][19]=h_time[19][18]=3;
h_time[18][20]=h_time[20][18]=3;
h_time[20][21]=h_time[21][10]=2;
h_time[16][23]=h_time[23][16]=6;
h_time[2][22]=h_time[22][2]=6;
h_time[22][23]=h_time[23][22]=11;
h_time[22][25]=h_time[25][22]=2;
h_time[22][24]=h_time[24][22]=18;
}
void set_p_time(){//构造飞机费用的邻接矩阵for(int i=1;i<=MAX;i++){
for(int j=1;j<=MAX;j++){
p_time[i][j]=INF;
}
}
p_time[1][2]=p_time [2][1]=8/2;//成都-西安
p_time[1][6]=p_time[6][1]=9/2;//成都-贵阳
p_time[2][3]=p_time[3][2]=5/2;//西安-郑州
p_time[3][10]=p_time[10][3]=3/2;//郑州-徐州
p_time[3][4]=p_time[4][3]=5/2;//郑州-武汉
p_time[4][5]=p_time[5][4]=4/2;//武汉-株洲
p_time[5][8]=p_time[8][5]=6/2;//株洲-广州
p_time[5][6]=p_time[6][5]=9/2;//株洲-贵阳
p_time[6][7]=p_time[7][6]=6/2;//贵阳-柳州
p_time[5][7]=p_time[7][5]=6/2;//株洲-柳州
p_time[9][7]=p_time[7][9]=2/2;//柳州-南宁
p_time[6][11]=p_time[11][6]=6/2;
p_time[1][11]=p_time[11][1]=11/2;
p_time[5][13]=p_time[13][5]=3/2;
p_time[8][12]=p_time[12][8]=1/2;
p_time[13][14]=p_time[14][13]=6/2;
p_time[13][15]=p_time[15][13]=8/2;
p_time[10][15]=p_time[15][10]=6/2;
p_time[10][17]=p_time[17][10]=6/2;
p_time[3][16]=p_time[16][3]=6/2;
p_time[16][17]=p_time[17][16]=1/2;
p_time[17][18]=p_time[18][17]=7/2;
p_time[18][19]=p_time[19][18]=3/2;
p_time[18][20]=p_time[20][18]=3/2;
p_time[20][21]=p_time[21][10]=2/2;
p_time[16][23]=p_time[23][16]=6/2;
p_time[2][22]=p_time[22][2]=6/2;
p_time[22][23]=p_time[23][22]=11/2;
p_time[22][25]=p_time[25][22]=2/2;
p_time[22][24]=p_time[24][22]=18/2;
}
void set_p_transer(){//构造飞机中转次数的邻接矩阵for(int i=1;i<=MAX;i++){
for(int j=1;j<=MAX;j++){
p_transer[i][j]=INF;
}
}
p_transer[1][2]=p_transer[2][1]=1;//成都-西安
p_transer[1][6]=p_transer[6][1]=1;//成都-贵阳
p_transer[2][3]=p_transer[3][2]=1;//西安-郑州
p_transer[3][10]=p_transer[10][3]=1;//郑州-徐州p_transer[3][4]=p_transer[4][3]=1;//郑州-武汉
p_transer[4][5]=p_transer[5][4]=1;//武汉-株洲
p_transer[5][8]=p_transer[8][5]=1;//株洲-广州
p_transer[5][6]=p_transer[6][5]=1;//株洲-贵阳
p_transer[6][7]=p_transer[7][6]=1;//贵阳-柳州
p_transer[5][7]=p_transer[7][5]=1;//株洲-柳州
p_transer[9][7]=p_transer[7][9]=1;//柳州-南宁
p_transer[6][11]=p_transer[11][6]=1;
p_transer[1][11]=p_transer[11][1]=1;
p_transer[5][13]=p_transer[13][5]=1;
p_transer[8][12]=p_transer[12][8]=1;
p_transer[13][14]=p_transer[14][13]=1;
p_transer[13][15]=p_transer[15][13]=1;
p_transer[10][15]=p_transer[15][10]=1;
p_transer[10][17]=p_transer[17][10]=1;
p_transer[3][16]=p_transer[16][3]=1;
p_transer[16][17]=p_transer[17][16]=1;
p_transer[17][18]=p_transer[18][17]=1;
p_transer[18][19]=p_transer[19][18]=1;
p_transer[18][20]=p_transer[20][18]=1;
p_transer[20][21]=p_transer[21][10]=1;
p_transer[16][23]=p_transer[23][16]=1;
p_transer[2][22]=p_transer[22][2]=1;
p_transer[22][23]=p_transer[23][22]=1;
p_transer[22][25]=p_transer[25][22]=1;
p_transer[22][24]=p_transer[24][22]=1;
}
void set_h_transer(){//构造火车中转次数的邻接矩阵for(int i=1;i<=MAX;i++){
for(int j=1;j<=MAX;j++){
h_transer[i][j]=INF;
}
}
h_transer[1][2]=h_transer[2][1]=1;//成都-西安
h_transer[1][6]=h_transer[6][1]=1;//成都-贵阳
h_transer[2][3]=h_transer[3][2]=1;//西安-郑州
h_transer[3][10]=h_transer[10][3]=1;//郑州-徐州
h_transer[3][4]=h_transer[4][3]=1;//郑州-武汉
h_transer[4][5]=h_transer[5][4]=1;//武汉-株洲
h_transer[5][8]=h_transer[8][5]=1;//株洲-广州
h_transer[5][6]=h_transer[6][5]=1;//株洲-贵阳
h_transer[6][7]=h_transer[7][6]=1;//贵阳-柳州
h_transer[5][7]=h_transer[7][5]=1;//株洲-柳州
h_transer[9][7]=h_transer[7][9]=1;//柳州-南宁
h_transer[6][11]=h_transer[11][6]=1;
h_transer[1][11]=h_transer[11][1]=1;
h_transer[5][13]=h_transer[13][5]=1;
h_transer[8][12]=h_transer[12][8]=1;
h_transer[13][14]=h_transer[14][13]=1;
h_transer[13][15]=h_transer[15][13]=1;
h_transer[10][15]=h_transer[15][10]=1;
h_transer[10][17]=h_transer[17][10]=1;
h_transer[3][16]=h_transer[16][3]=1;
h_transer[16][17]=h_transer[17][16]=1;
h_transer[17][18]=h_transer[18][17]=1;
h_transer[18][19]=h_transer[19][18]=1;
h_transer[18][20]=h_transer[20][18]=1;
h_transer[20][21]=h_transer[21][10]=1;
h_transer[16][23]=h_transer[23][16]=1;
h_transer[2][22]=h_transer[22][2]=1;
h_transer[22][23]=h_transer[23][22]=1;
h_transer[22][25]=h_transer[25][22]=1;
h_transer[22][24]=h_transer[24][22]=1;
}
void pr(int i){//用来选择输出第i个城市的名称
if(i==1 && delcity[1]!=1 && delcity[2]!=1 && delcity[3]!=1 && delcity[4]!=1 && delcity[5]!=1 )cout<<"成都.";
if(i==2 && delcity[1]!=2 && delcity[2]!=2 && delcity[3]!=2 && delcity[4]!=2 && delcity[5]!=2 )cout<<"西安.";
if(i==3 && delcity[1]!=3 && delcity[2]!=3 && delcity[3]!=3 && delcity[4]!=3 && delcity[5]!=3 )cout<<"郑州.";
if(i==4 && delcity[1]!=4 && delcity[2]!=4 && delcity[3]!=4 && delcity[4]!=4 && delcity[5]!=4 )cout<<"武汉.";
if(i==5 && delcity[1]!=5 && delcity[2]!=5 && delcity[3]!=5 && delcity[4]!=5 && delcity[5]!=5 )cout<<"株洲.";
if(i==6 && delcity[1]!=6 && delcity[2]!=6 && delcity[3]!=6 && delcity[4]!=6 && delcity[5]!=6 )cout<<"贵阳.";
if(i==7 && delcity[1]!=7 && delcity[2]!=7 && delcity[3]!=7 && delcity[4]!=7 && delcity[5]!=7 )cout<<"柳州.";