📄 main.cpp
字号:
//本程序是由四川师范大学2005级计算机科学学院计算机科学与技术系
//孙亮编写
//学号:2005111034
//2007.5.1
////////////////////////////////////////////////////////////////
#include <windows.h>
#include <stdio.h>
#include <crtdbg.h>
#include <string.h>
#include<iostream.h>
#include <malloc.h>
#define INF 65535 //定义一个最大数定为无穷值
#define MAX 23
static int c_number=13;
static int k=0;
static int v=0,z=0,r=0,t=0;
typedef struct zhu
{
int c_cost;
int c_time;
int f_cost;
int f_time;
}zhu;
zhu m[20],x[20],n[20];
typedef int costAdj[MAX+1][MAX+1];//图邻接矩阵从1开始记数
int Path[MAX+1][MAX+1];//图邻接矩阵从1开始记数
typedef struct unDiGraph
{
int numVerts; //结点
costAdj cost; //邻接矩阵
}unDiGraph,*UNG; //图的定义
typedef struct c_edit
{
char a[10];
}c_edit;
c_edit add[10];
costAdj B,L;
int pr(int i,int j)
{
int h=0;
if (j==0) {
h=i;
}
else if (j==1)
{
cin>>add[i].a;
}
switch(h)//运用switch语句。
{
case(0):cout<<"";
break;
case(1) : cout<<"成都 ";
break;
case(2) : cout<<"西安 ";
break;
case(3) : cout<<"郑州 ";
break;
case(4) : cout<<"武汉 ";
break;
case(5) : cout<<"株洲 ";
break;
case(6) : cout<<"贵阳 ";
break;
case(7) : cout<<"柳州 ";
break;
case(8) : cout<<"广州 ";
break;
case(9) : cout<<"南宁 ";
break;
case(10) : cout<<"徐州 ";
break;
case(11) : cout<<"北京 ";
break;
case(12) : cout<<"天津 ";
break;
case(13) : cout<<"上海 ";
break;
default:
cout<<add[i-13].a;
}
return 1;
}
//输出城市列表及相应代码
void pri()
{
int i;
cout<<" 城市及其代码"<<endl<<endl<<endl;
cout<<" *********************************************"<<endl;
for (i=1;i<=c_number;i++)
{
cout<<i<<".";
pr(i,0);
}
cout<<endl<<" *********************************************"<<endl<<endl<<endl<<endl<<endl<<endl;
}
//构造带权(费用)图 返回首地址G:
unDiGraph *CreateCostG(int o)//火车的花费的存贮和编辑功能
{
unDiGraph *G;
int i,j;
int a=0,b=0,f,h=1;
if(!(G=(unDiGraph *)malloc(sizeof(unDiGraph)))) //为G分配存储空间。
{
return(NULL);
}
for(i=1;i<c_number+1;i++)
{
for(j=1;j<c_number+1;j++)
{
G->cost[i][j]=INF; //初始化使G->cost[i][j]为无穷。
}
}
G->numVerts=c_number;
G->cost[1][6]=G->cost[6][1]=96;
G->cost[1][2]=G->cost[2][1]=84;
G->cost[2][3]=G->cost[3][2]=51;
G->cost[3][4]=G->cost[4][3]=53;
G->cost[4][5]=G->cost[5][4]=40;
G->cost[5][6]=G->cost[6][5]=90;
G->cost[5][8]=G->cost[8][5]=67;
G->cost[5][7]=G->cost[7][5]=67;
G->cost[6][7]=G->cost[7][6]=60;
G->cost[7][9]=G->cost[9][7]=25;
G->cost[3][11]=G->cost[11][3]=69;
G->cost[11][12]=G->cost[12][11]=13;
G->cost[12][10]=G->cost[10][12]=67;
G->cost[3][10]=G->cost[10][3]=34;
G->cost[13][10]=G->cost[10][13]=65;
G->cost[13][5]=G->cost[5][13]=118;
if (o) {
while(h==1)
{
v=v+1;
pri();
cout<<"火车花费编辑"<<endl;
cout<<"请输入开始城市的代码"<<endl;
cin>>a;
cout<<"请输入结尾城市的代码"<<endl;
cin>>b;
cout<<"请输入你的两地花费"<<endl;
cin>>m[v].c_cost;
n[v].c_cost=a;
x[v].c_cost=b;
cout<<"请选择"<<endl;
cout<<"*********************************"<<endl;
cout<<"1:继续更改城市费用"<<endl;
cout<<"0:返回上一级菜单"<<endl;
cout<<"*********************************"<<endl;
cin>>h;
switch(h) {
case 1:
h=1;
break;
case 0:
h=0;
break;
default:{
cout<<"选择出错"<<endl;
}
}
}
}
f=v+1;
while (v--) {
G->cost[n[v].c_cost][x[v].c_cost]=m[v].c_cost;
}
v=f;
return(G);
}
//构造带权(时间)图 返回首地址G:
unDiGraph *CreateTimeG(int o)//火车的时间的存贮和编辑功能
{
unDiGraph *G;
int i,j;
int a=0,b=0,f,h=1;
if(!(G=(unDiGraph *)malloc(sizeof(unDiGraph)))) //为G分配存储空间。
{
return(NULL);
}
for(i=1;i<c_number+1;i++)
{
for(j=1;j<c_number+1;j++)
{
G->cost[i][j]=INF;//初始化使G->cost[i][j]为无穷。
}
}
G->numVerts=c_number;
G->cost[1][6]=G->cost[6][1]=9;
G->cost[1][2]=G->cost[2][1]=8;
G->cost[2][3]=G->cost[3][2]=5;
G->cost[3][4]=G->cost[4][3]=5;
G->cost[4][5]=G->cost[5][4]=4;
G->cost[5][6]=G->cost[6][5]=9;
G->cost[5][7]=G->cost[7][5]=6;
G->cost[5][8]=G->cost[8][5]=6;
G->cost[6][7]=G->cost[7][6]=6;
G->cost[7][9]=G->cost[9][7]=2;
G->cost[3][11]=G->cost[11][3]=6;
G->cost[11][12]=G->cost[12][11]=1;
G->cost[12][10]=G->cost[10][12]=6;
G->cost[3][10]=G->cost[10][3]=3;
G->cost[13][10]=G->cost[10][13]=6;
G->cost[13][5]=G->cost[5][13]=11;
if (o) {
while(h==1)
{
z=z+1;
pri();
cout<<"火车时间编辑"<<endl;
cout<<"请输入开始城市的代码"<<endl;
cin>>a;
cout<<"请输入结尾城市的代码"<<endl;
cin>>b;
cout<<"请输入你的两地时间"<<endl;
cin>>m[z].c_time;
n[z].c_time=a;
x[z].c_time=b;
cout<<"请选择"<<endl;
cout<<"*********************************"<<endl;
cout<<"1:继续更改城市时间"<<endl;
cout<<"0:返回上一级菜单"<<endl;
cout<<"*********************************"<<endl;
cin>>h;
switch(h) {
case 1:
h=1;
break;
case 0:
h=0;
break;
default:{
cout<<"选择出错"<<endl;
}
}
}
}
f=z+1;
while (z--) {
G->cost[n[z].c_time][x[z].c_time]=m[z].c_time;
}
z=f;
return(G);
}
unDiGraph *CreateTimeF(int o)//飞机的时间的存贮和编辑功能
{
unDiGraph *G;
int i,j;
int a=0,b=0,f,h=1;
if(!(G=(unDiGraph *)malloc(sizeof(unDiGraph)))) //为G分配存储空间。
{
return(NULL);
}
for(i=1;i<c_number+1;i++)
{
for(j=1;j<c_number+1;j++)
{
G->cost[i][j]=INF;//初始化使G->cost[i][j]为无穷。
}
}
G->numVerts=c_number;
G->cost[1][6]=G->cost[6][1]=3;
G->cost[1][2]=G->cost[2][1]=2;
G->cost[2][3]=G->cost[3][2]=1;
G->cost[3][4]=G->cost[4][3]=2;
G->cost[4][5]=G->cost[5][4]=4;
G->cost[5][6]=G->cost[6][5]=3;
G->cost[5][7]=G->cost[7][5]=6;
G->cost[5][8]=G->cost[8][5]=6;
G->cost[6][7]=G->cost[7][6]=6;
G->cost[7][9]=G->cost[9][7]=2;
G->cost[3][11]=G->cost[11][3]=6;
G->cost[11][12]=G->cost[12][11]=1;
G->cost[12][10]=G->cost[10][12]=2;
G->cost[3][10]=G->cost[10][3]=3;
G->cost[13][10]=G->cost[10][13]=6;
G->cost[13][5]=G->cost[5][13]=1;
if (o) {
while(h==1)
{
t=t+1;
pri();
cout<<"飞机时间编辑"<<endl;
cout<<"请输入开始城市的代码"<<endl;
cin>>a;
cout<<"请输入结尾城市的代码"<<endl;
cin>>b;
cout<<"请输入你的两地时间"<<endl;
cin>>m[t].f_time;
n[t].f_time=a;
x[t].f_time=b;
cout<<"请选择"<<endl;
cout<<"*********************************"<<endl;
cout<<"1:继续更改城市时间"<<endl;
cout<<"0:返回上一级菜单"<<endl;
cout<<"*********************************"<<endl;
cin>>h;
switch(h) {
case 1:
h=1;
break;
case 0:
h=0;
break;
default:{
cout<<"选择出错"<<endl;
}
}
}
}
f=t+1;
while (t--) {
G->cost[n[t].f_time][x[t].f_time]=m[t].f_time;
}
t=f;
return(G);
}
unDiGraph *CreateCostF(int o)//飞机花费的存贮和编辑功能
{
unDiGraph *G;
int i,j;
int a=0,b=0,f,h=1;
if(!(G=(unDiGraph *)malloc(sizeof(unDiGraph)))) //为G分配存储空间。
{
return(NULL);
}
for(i=1;i<c_number+1;i++)
{
for(j=1;j<c_number+1;j++)
{
G->cost[i][j]=INF; //初始化使G->cost[i][j]为无穷。
}
}
G->numVerts=c_number;
G->cost[1][6]=G->cost[6][1]=960;
G->cost[1][2]=G->cost[2][1]=840;
G->cost[2][3]=G->cost[3][2]=501;
G->cost[3][4]=G->cost[4][3]=530;
G->cost[4][5]=G->cost[5][4]=400;
G->cost[5][6]=G->cost[6][5]=900;
G->cost[5][8]=G->cost[8][5]=670;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -