?? new_file.cpp
字號:
{
for(int pi13=0;pi13<stage[pi12].line_in;pi13++)
{
int tmp_ji7;
tmp_ji7=strcmp(zhongzhuan[zhongzhuan_counter].end_line,stage[pi12].biaoji[pi13].way);
if(tmp_ji7==0)
{
middle1=stage[pi12].biaoji[pi13].num;
break;
}
}
break;
}
}
zhongzhuan[zhongzhuan_counter].lu_cheng=abs(first-middle0)+abs(last-middle1);
///zhongzhuan[zhongzhuan_counter]=abs(bus_line[god0[pi4]])+abs();///經過的站數輛還沒定
zhongzhuan_counter++;/////中轉站的數目變多
}
}
}
if(zhongzhuan_counter==0)goto lab_change3;
///////////////////****得到了線路的交點****/////////////////////
///////***想通過排序的方法得到路徑由短到長的排列****////////
///////** 交換兩個zhongzhuan結構體的值 **///////
for(int bee0=0;bee0<zhongzhuan_counter;bee0++)
for(int bee1=0;bee1<zhongzhuan_counter;bee1++)
if(zhongzhuan[bee0].lu_cheng<zhongzhuan[bee1].lu_cheng)
{
least.begin_id=zhongzhuan[bee0].begin_id;
strcpy(least.begin_line,zhongzhuan[bee0].begin_line);
least.end_id=zhongzhuan[bee0].end_id;
strcpy(least.end_line,zhongzhuan[bee0].end_line);
least.lu_cheng=zhongzhuan[bee0].lu_cheng;
strcpy(least.round,zhongzhuan[bee0].round);
zhongzhuan[bee0].begin_id=zhongzhuan[bee1].begin_id;
strcpy(zhongzhuan[bee0].begin_line,zhongzhuan[bee1].begin_line);
zhongzhuan[bee0].end_id=zhongzhuan[bee1].end_id;
strcpy(zhongzhuan[bee0].end_line,zhongzhuan[bee1].end_line);
zhongzhuan[bee0].lu_cheng=zhongzhuan[bee1].lu_cheng;
strcpy(zhongzhuan[bee0].round,zhongzhuan[bee1].round);
zhongzhuan[bee1].begin_id=least.begin_id;
strcpy(zhongzhuan[bee1].begin_line,least.begin_line);
zhongzhuan[bee1].end_id=least.end_id;
strcpy(zhongzhuan[bee1].end_line,least.end_line);
zhongzhuan[bee1].lu_cheng=least.lu_cheng;
strcpy(zhongzhuan[bee1].round,least.round);
}
////////***上面**///////
// cout<<"達到了這一步"<<endl;
for(int pi8=0;pi8<zhongzhuan_counter;pi8++)
{
if(pi8==0)cout<<"沒有直達車,需要轉車"<<endl;
cout<<"第"<<pi8+1<<"種方法為: "<<"起點"<<zhongzhuan[pi8].begin_line<<"->到->"<<zhongzhuan[pi8].round<<"下車坐"<<zhongzhuan[pi8].end_line<<"到目的. "<<"總的路程為"<<zhongzhuan[pi8].lu_cheng<<endl;
}
cout<<"提示:輸入相應的乘車編號可以具體查看經過哪些站點,輸入0退出"<<endl;
cin>>tishi;
if(tishi==0)break;////輸入為0則跳出
int use_endl=0;/////用于輸出回車符
///////////////////////////////////////////////////**以下的程序是實現各個站點的輸出**///////////////////////////////////////////////////
if(tishi<=zhongzhuan_counter)////輸入的選擇方案可以找到
{
int way_begin;////存放起始的站臺在起始公交線的站數
int way_middle0;////存放中轉站在起始公交線的站數
int way_middle1;////存放中轉站在結束公交線的站數
int way_end;////存放終點在結束公交線路的站數
//////////尋找起點站在公交路線上的位置//////////
for(int self0=0;self0<=bus_line[zhongzhuan[tishi-1].begin_id].geshu;self0++)
{
int weak0;
int weak1;
weak0=strcmp(input1,bus_line[zhongzhuan[tishi-1].begin_id].line[self0]);
weak1=strcmp(zhongzhuan[tishi-1].round,bus_line[zhongzhuan[tishi-1].begin_id].line[self0]);
if(weak0==0)way_begin=self0;/////如果找到與起點相同的站點,記錄站數
if(weak1==0)way_middle0=self0;////在起點線找到與中轉相同的點,記錄站數
}
for(int self1=0;self1<=bus_line[zhongzhuan[tishi-1].end_id].geshu;self1++)
{
int weak2;
int weak3;
weak2=strcmp(input2,bus_line[zhongzhuan[tishi-1].end_id].line[self1]);
weak3=strcmp(zhongzhuan[tishi-1].round,bus_line[zhongzhuan[tishi-1].end_id].line[self1]);
if(weak2==0)way_end=self1;/////如果找到與起點相同的站點,記錄站數
if(weak3==0)way_middle1=self1;////在起點線找到與中轉相同的點,記錄站數
}
if(way_begin>=way_middle0)
{
cout<<"從起點站到中轉站所坐的公交線為"<<zhongzhuan[tishi-1].begin_line<<"路,經過的各站點為:"<<endl;
cout<<endl;
for(int self2=way_begin;self2>=way_middle0;self2--)
{
out_enter++;
if(out_enter%6==0)cout<<endl;////每8個站點一行輸出
cout<<bus_line[zhongzhuan[tishi-1].begin_id].line[self2]<<" ->";
}
}
else
{
cout<<"從起點站到中轉站所坐的公交路線為"<<zhongzhuan[tishi-1].begin_line<<"路,經過的各站點為:"<<endl;
cout<<endl;
for(int self3=way_begin;self3<=way_middle0;self3++)
{
out_enter++;
if(out_enter%6==0)cout<<endl;
cout<<bus_line[zhongzhuan[tishi-1].begin_id].line[self3]<<" ->";
}
}
cout<<endl;
cout<<endl;
out_enter=0;
if(way_end>=way_middle1)
{
cout<<"從中轉站到終點站所坐的公交路線為 "<<zhongzhuan[tishi-1].end_line<<"路,經過的各站點為:"<<endl;
// cout<<endl;
for(int self4=way_middle1;self4<=way_end;self4++)
{
out_enter++;
if(out_enter%6==0)cout<<endl;////每8個站點一行輸出
cout<<bus_line[zhongzhuan[tishi-1].end_id].line[self4]<<" ->";
}
}
else
{
cout<<"從中轉站到終點站所坐的公交線路為 "<<zhongzhuan[tishi-1].end_line<<" 路,經過的各站點為:"<<endl;
// cout<<endl;
for(int self5=way_middle1;self5>=way_end;self5--)
{
out_enter++;
if(out_enter%6==0)cout<<endl;
cout<<bus_line[zhongzhuan[tishi-1].end_id].line[self5]<<" ->";
}
}
cout<<endl;
}
else
cout<<"輸入的選擇方案有錯誤"<<endl;
break;
}
lab_change3: if(zhongzhuan_counter==0&&same_counter0==0)
{
cout<<"換乘一次車沒有方案,只有換乘兩次的情況"<<endl;
///**以下一段程序的作用是將終點**////
for(int pp0=0;pp0<stage[end_stage].line_in;pp0++)////////遍歷所有經過這個站點的路線
{
for(int pp1=0;pp1<=bus_num;pp1++)
{
int tmp_use;
tmp_use=strcmp(stage[end_stage].biaoji[pp0].way,bus_line[pp1].name);
if(tmp_use==0)////尋找公交車號相同的,將經過的站臺的存放到line_all2
{
for(int pp2=0;pp2<=bus_line[pp1].geshu;pp2++)
{
int tmp10;
for(int pp3=0;pp3<=cross_stage2;pp3++)///////查詢是不是有重復的站點的進入,防止重復
{
tmp10=strcmp(bus_line[pp1].line[pp2],line_all2[pp3]);
if(tmp10==0)
{
enable_add2=0;
break;
}
}
if(enable_add2==1)
{
strcpy(line_all2[cross_stage2],bus_line[pp1].line[pp2]);
cross_stage2++;
}
enable_add2=1;
}
}
}
}
//測試 cout<<"cross_stage2 的值為"<<cross_stage2<<endl;
//測試 cout<<"cross_stage 的值為"<<cross_stage<<endl;
/////**到此為止,已經將line_all2[1000][20]數組初始化完,即終點站所能到達的站點,下一步是line_all2數組所能達到的路線,存放在line_num2[200][20]數組里**/////
for(int jj0=0;jj0<cross_stage2;jj0++)
for(int jj1=0;jj1<=stage_num;jj1++)
{
int we;
we=strcmp(line_all2[jj0],stage[jj1].name);
if(we==0)///相同的站點則將此站點所經過的路線值導入
{
for(int jj2=0;jj2<stage[jj1].line_in;jj2++)
{
for(int jj3=0;jj3<=line_num_flag2;jj3++)/////查詢現有的line_num數組里是不是已經有相同的值
{
int tmp_ji1;
tmp_ji1=strcmp(stage[jj1].biaoji[jj2].way,line_num2[jj3]);
if(tmp_ji1==0)
{
line_num_enable2=0;
break;
}
}
if(line_num_enable2==1)/////允許計入到數組
{
strcpy(line_num2[line_num_flag2],stage[jj1].biaoji[jj2].way);
line_num_flag2++;
}
line_num_enable2=1;
}
}
}
//測試用到的代碼cout<<"得到的line_num_flag2的值為"<<line_num_flag2<<endl;
//測試用到的代碼 cout<<"得到的line_num_flag的值為"<<line_num_flag<<endl;
// for(int qp0=0;qp0<line_num_flag;qp0++)
// cout<<qp0<<"經過起點的轉乘公交路線為"<<line_num[qp0]<<endl;
// for(int qp1=0;qp1<line_num_flag2;qp1++)
// cout<<qp1<<"經過終點的轉乘公交路線為"<<line_num2[qp1]<<endl;
////**到現在為止,已經得到了可以從終點轉乘車輛的公交線路號,存放在line_num2[200][20]里,數量為line_num_flag2**////
///**在上面已經得到了從起點出發的公交線路號,存放在line_num[200][20]里,數量為line_num_flag**///
char same2_middle[500][20];/////存放的是第一道轉車到第二道轉車的路線
int same2_middle_flag=0;//////第一道轉車到第二道轉車的方案的個數
int same2_middle_enable=1;////使用的原因是防止相同的公交線路進入這個same2_middle數組里
// char same2_first[200][20];/////起始站到第一道轉車的路線
int same2_first_flag=0;/////起始站到第一道轉車的方案個數
int same2_first_enable=1;////防止相同的公交線路進入這個數組same2_first[200][20]
// char same2_end[200][20];////第二道轉車到終點的公交路線
int same2_end_flag=0;/////第二道轉車到終點的可選方案的個數
int same2_end_enable=1;////防止相同的公交線路進入這個數組same2_end[200][20]
for(int xz1=0;xz1<line_num_flag;xz1++)
for(int xz2=0;xz2<line_num_flag2;xz2++)
{
int tmp_use;
tmp_use=strcmp(line_num[xz1],line_num2[xz2]);
if(tmp_use==0)/////如果兩個中轉的路線集合之間有交集
{
for(int xz3=0;xz3<same2_middle_flag;xz3++)////本層循環的作用是在已經建立好的數組中看是否有重復的公交路線進入
{
int tmp_cjc;
tmp_cjc=strcmp(line_num[xz1],same2_middle[xz3]);
if(tmp_cjc==0)////如果有,則應該禁止加入
{
same2_middle_enable=0;
break;
}
}
if(same2_middle_enable==1)
{
strcpy(same2_middle[same2_middle_flag],line_num[xz1]);
same2_middle_flag++;
}
same2_middle_enable=1;////為下一次的加入作準備
}
}
//測試 cout<<"same2_middle_flag的值為"<<same2_middle_flag<<endl;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -