📄 new_file.cpp
字号:
}
}
infile.close();
}
/////////*****将TXT文档中的值写到bus_line结构体中*****//////////
///////****以下函数的的作用是处理站点所对应的公交线路的值****/////////
////////**以下的函数的处理可以在一个bus_line结构体数组中取值**///////
int judge(char*p1,char*p2)
{
int kk;
kk=strcmp(p1,p2);
if(kk==0)
return 1;/////相等为1,不相等为0
else
return 0;
}
void gene_station(void)
{
int tmp1;///记录200条公交线进展到了哪一个
int tmp2;////一条公交线所经历的站点数
int tmp3;///
int tmp4=0;////标记有了多少个站台库
int enable=1;/////标记要插入的的是不是有了,起先是都允许插入的,如果有相同的就不允许插入
int start_up=1;/////第一次初始化的标志位
int counter=0;////纪录这是经过这一个站点的第几条线
int flag_tmp=1;
for(tmp1=0;tmp1<=bus_num;tmp1++)////遍历所有的公交线
{
//test else///////////***在以后的路线中,首先要查找和前面的是不是有重复,没有重复再加入新的站点****///////////////
//test {
for(tmp2=0;tmp2<=bus_line[tmp1].geshu;tmp2++)///tmp2 指在一条公交线所经过的站点数
{
////查找和前面的是不是有重复///
for(tmp3=0;tmp3<=stage_num;tmp3++)/////tmp3标记现有的站点的数量
{
int cao;
cao=strcmp(bus_line[tmp1].line[tmp2],stage[tmp3].name);
if(cao==0)////如果相同则将车辆信息加入到这一个站点
{
stage[0].num=0;
strcpy(stage[tmp3].biaoji[stage[tmp3].line_in].way,bus_line[tmp1].name);
stage[tmp3].biaoji[stage[tmp3].line_in].num=tmp2;////一辆车的下行站点数
enable=0;
stage[tmp3].line_in++;
break;
}
}
//////////////////判断重复结束///////////////////////
if(enable==1)////在查找的过程中如果没有发现相同的则允许加入新的站点
{ ///**注意在新的站点加入的过程中,要将当前值纪录进去**///
stage_num++;
tmp4++;
strcpy(stage[stage_num].name,bus_line[tmp1].line[tmp2]);
strcpy(stage[stage_num].biaoji[0].way,bus_line[tmp1].name);
stage[stage_num].biaoji[0].num=tmp2;////一辆车的下行站点数
stage[stage_num].num=stage_num;
stage[stage_num].line_in=1;/////标记入栈的已经有了一个
}
enable=1;/////为下一个站点的进入而准备
}
//test }
}
}
////////****站点录入结束,已经成功****///////////
void main(void)
{
int begin_stage=-1;/////起点站所在整个stage队列数组中的位置
int end_stage=-1;////终点站在整个stage队列数组中的位置
int correct0=0;
int correct1=0;
int correct2=0;
//////////////////////////////////////////////
char same[20][20];//////用于记录不需要转车的交集
char same1_1[20][20];////用于记录需要转车时起点到中途的路径
int same1_1counter=0;
char same1_2[20][20];///用于记录需要转车时从中转站到终点的路径,和上面一一对应
int same1_2counter=0;
///////////////////////////////////////////////////////
int same_counter0=0;/////用于记录不要转车的交集个数
int same_counter1=0;/////用于记录要转一次车的交集个数
int same_counter2=0;/////用于记录要转两次车的交集个数
int enable_add=1;/////看当前的车站点是不是可以加入
int cross_stage=0;///计算从起始站可以到达的站台的集合
char line_all[1000][20];/////用于记录从起点站出发所有可能到达站的集合
char line_num[500][20];/////存放line_all数组站台所经过的公交车的路数
int line_num_flag=0;/////已经有多少公交车进入line_num数组
int line_num_enable=1;
int zhongzhuan_counter=0;
////////////*** 以下的定义是为了换乘两次的情况服务的 ***////////////
int enable_add2=1;
int cross_stage2=0;
char line_all2[1000][20];
char line_num2[500][20];
int line_num_flag2=0;
int line_num_enable2=1;
int zhongzhuan_counter2=0;
////////** 换乘两次的定义结束 ***///////
int out_enter=0;
change zhongzhuan[100];/////查询时的中转站
change least;///////存放临时的zhongzhuan数组,用于排序
read_file();
gene_station();
//////////////////////////////////////
while(1)
{
int fun;
char input_line[10];
int boy0;
int girl0;
int boy1;
int girl1;
char input_stage[20];
char mind;
int compare;
int she;/////用在模糊函数的处理中
int xiao0[100];///找到最大权值的ID(num),有可能存在相同的权值
int xiao0_counter=0;
int xiao1=0;////临时的值,
int tishi=0;/////输入乘车的选择方案以便具体给出经过哪些站点
int line_cmp_result;
cout<<" 功能菜单选项"<<endl;
cout<<endl;
cout<<" 0.退出"<<endl;
cout<<endl;
cout<<" 1.查询某一条公交线的状况"<<endl;
cout<<endl;
cout<<" 2.查询经过某一个站点的所有的公交线路"<<endl;
cout<<endl;
cout<<" 3.查询从起点到终点的所有路径"<<endl;
cout<<endl;
cin>>fun;
switch(fun)
{
case 0:
break;
case 1:
cout<<" 请输入公交的路线"<<endl;
cin>>input_line;
for(boy0=0;boy0<=bus_num;boy0++)
{
line_cmp_result=strcmp(input_line,bus_line[boy0].name);
if(line_cmp_result==0)
{
for(boy1=0;boy1<=bus_line[boy0].geshu;boy1++)
{
if(boy1%5==0)cout<<endl;
cout<<bus_line[boy0].line[boy1]<<" ";
}
correct0=1;////
}
}
if(correct0==0)
{cout<<"输入的站点有误"<<endl;
break;
}
cout<<endl;
break;
case 2:
cout<<" 请输入要查询的站点"<<endl;
cin>>input_stage;
for(girl0=0;girl0<=stage_num;girl0++)
{
compare=strcmp(input_stage,stage[girl0].name);
if(compare==0)
{
cout<<"经过的公交线为为"<<endl;
for(girl1=0;girl1<stage[girl0].line_in;girl1++)
{
if(girl1%5==0)cout<<endl;
cout<<stage[girl0].biaoji[girl1].way<<"路 ";
}
correct1=1;
}
}
if(correct1==0)
{
xiao0_counter=0;
cout<<"输入有错误"<<endl;
for(she=0;she<=stage_num;she++)
{
stage[she].quan=mohu(input_stage,stage[she].name);
if(stage[she].quan>=xiao1)
{
xiao1=stage[she].quan;/////找出整个的最大权值
}
}
for(she=0;she<=stage_num;she++)
{
if(stage[she].quan==xiao1)
{
xiao0[xiao0_counter]=stage[she].num;
xiao0_counter++;
}
}
for(she=0;she<xiao0_counter;she++)
cout<<"你是不是在找 "<<stage[xiao0[she]].name<<"?"<<endl;
break;
}
cout<<endl;
break;
case 3:
int i_beg;
int i_end;
int i_beg_enable=1;
int i_end_enable=1;
cout<<"请输入起始站点的名字"<<endl;
cin>>input1;
cout<<"请输入终点的站名"<<endl;
cin>>input2;
for(int i=0;i<=stage_num;i++)
{
i_beg=strcmp(input1,stage[i].name);
i_end=strcmp(input2,stage[i].name);
if(i_beg==0)///////起始站找到了相同的点
{
begin_stage=stage[i].num;
i_beg_enable=0;
}
if(i_end==0)
{
end_stage=stage[i].num;
i_end_enable=0;
}
}
if(i_beg_enable==1||i_end_enable==1)
{
cout<<"输入的站点有错误"<<endl;
if(i_beg_enable==1)
{
xiao0_counter=0;
cout<<"输入起始站有错误"<<endl;
for(she=0;she<=stage_num;she++)
{
stage[she].quan=mohu(input1,stage[she].name);
if(stage[she].quan>=xiao1)
{
xiao1=stage[she].quan;/////找出整个的最大权值
}
}
for(she=0;she<=stage_num;she++)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -