?? 最終修改.txt
字號:
///**same1_1[]存放的是起點到中轉站得車號,same1_2[]存放的是終點到中轉站的車號,求倆個的相交點即為中轉點**///////
int god0[20];/////起始站的ID
int god0_flag=0;////起始站的入棧個數
int god1[20];/////終點站的id
int god1_flag=0;////終點站的入棧個數
for(int pi0=0;pi0<same1_1counter;pi0++)
for(int pi2=0;pi2<=bus_num;pi2++)//////首先要尋找到是在哪一個bus_line[]里////////
{
int tmpp_use;
tmpp_use=strcmp(bus_line[pi2].name,same1_1[pi0]);
if(tmpp_use==0)
{
god0[god0_flag]=bus_line[pi2].id;
god0_flag++;
}
}
/////////////////////////////二號//////////////////
for(int pi1=0;pi1<same1_2counter;pi1++)
for(int pi3=0;pi3<=bus_num;pi3++)
{
int tmmp_use;
tmmp_use=strcmp(bus_line[pi3].name,same1_2[pi1]);
if(tmmp_use==0)
{
god1[god1_flag]=bus_line[pi3].id;
god1_flag++;
}
}
//cout<<"達到了這一步"<<endl;
//////////////////***以下函數是得到兩條路線的共同站點round[]***//////////////
int useful0;
for(int pi4=0;pi4<god0_flag;pi4++)
for(int pi5=0;pi5<god1_flag;pi5++)
{
///////***對于每一條路線而言要比較所有的站點*****//////
for(int pi6=0;pi6<=bus_line[god0[pi4]].geshu;pi6++)
for(int pi7=0;pi7<=bus_line[god1[pi5]].geshu;pi7++)
{
useful0=strcmp(bus_line[god0[pi4]].line[pi6],bus_line[god1[pi5]].line[pi7]);
if(useful0==0)
{
int first;////記錄起點在那一條公交線上的位置
int middle0;///記錄中轉站在起點線上的位置
int middle1;////記錄中轉站在終點線上的位置
int last;////記錄終點在那一條線上的位置
strcpy(zhongzhuan[zhongzhuan_counter].begin_line,bus_line[god0[pi4]].name);
strcpy(zhongzhuan[zhongzhuan_counter].end_line,bus_line[god1[pi5]].name);
strcpy(zhongzhuan[zhongzhuan_counter].round,bus_line[god0[pi4]].line[pi6]);
zhongzhuan[zhongzhuan_counter].begin_id=god0[pi4];
zhongzhuan[zhongzhuan_counter].end_id=god1[pi5];
/////////****以下函數的作用是得到站數值****/////////
////////***首先計算從起點到中轉站的值****/////////
for(int pi8=0;pi8<stage[begin_stage].line_in;pi8++)
{
int tmp_ji4;
tmp_ji4=strcmp(zhongzhuan[zhongzhuan_counter].begin_line,stage[begin_stage].biaoji[pi8].way);
if(tmp_ji4==0)
{
first=stage[begin_stage].biaoji[pi8].num;
break;
////得到起點站的在整個隊列中的編號
}
}
////得到終點站的在整個隊列中的編號
for(int pi9=0;pi9<stage[end_stage].line_in;pi9++)
{
int tmp_ji5;
tmp_ji5=strcmp(zhongzhuan[zhongzhuan_counter].end_line,stage[end_stage].biaoji[pi9].way);
if(tmp_ji5==0)
{
last=stage[end_stage].biaoji[pi9].num;
break;
}
}
for(int pi10=0;pi10<=stage_num;pi10++)
{
int now;
now=strcmp(zhongzhuan[zhongzhuan_counter].round,stage[pi10].name);
if(now==0)
{
for(int pi11=0;pi11<stage[pi10].line_in;pi11++)
{
int tmp_ji6;
tmp_ji6=strcmp(zhongzhuan[zhongzhuan_counter].begin_line,stage[pi10].biaoji[pi11].way);
if(tmp_ji6==0)
{
middle0=stage[pi10].biaoji[pi11].num;
break;
}
}
break;
}
}
for(int pi12=0;pi12<=stage_num;pi12++)
{
int now1;
now1=strcmp(zhongzhuan[zhongzhuan_counter].round,stage[pi12].name);
if(now1==0)
{
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++;/////中轉站的數目變多
}
}
}
cout<<zhongzhuan_counter<<endl;
///////////////////****得到了線路的交點****/////////////////////
///////***想通過排序的方法得到路徑由短到長的排列****////////
///////** 交換兩個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;
}
}
labnext: cout<<" 想繼續嗎(Y/N)?"<<endl;
cin>>mind;
if(mind=='Y'||mind=='y')
{
zhongzhuan_counter=0;
line_num_enable=1;
line_num_flag=0;
cross_stage=0;
enable_add=1;
same_counter2=0;
same_counter1=0;
same_counter0=0;
same1_2counter=0;
same1_1counter=0;
correct2=0;
correct1=0;
correct0=0;
end_stage=-1;
begin_stage=-1;
out_enter=0;//////用于經過的站點輸出時的回車輸出
xiao1=0;////臨時的值
xiao0_counter=0;
continue;
}
else
break;
}
/////////////程序完成////////////////
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -