?? new_file.cpp
字號:
}
}
infile.close();
}
/////////*****將TXT文檔中的值寫到bus_line結構體中*****//////////
///////****以下函數(shù)的的作用是處理站點所對應的公交線路的值****/////////
////////**以下的函數(shù)的處理可以在一個bus_line結構體數(shù)組中取值**///////
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;////一條公交線所經(jīng)歷的站點數(shù)
int tmp3;///
int tmp4=0;////標記有了多少個站臺庫
int enable=1;/////標記要插入的的是不是有了,起先是都允許插入的,如果有相同的就不允許插入
int start_up=1;/////第一次初始化的標志位
int counter=0;////紀錄這是經(jīng)過這一個站點的第幾條線
int flag_tmp=1;
for(tmp1=0;tmp1<=bus_num;tmp1++)////遍歷所有的公交線
{
//test else///////////***在以后的路線中,首先要查找和前面的是不是有重復,沒有重復再加入新的站點****///////////////
//test {
for(tmp2=0;tmp2<=bus_line[tmp1].geshu;tmp2++)///tmp2 指在一條公交線所經(jīng)過的站點數(shù)
{
////查找和前面的是不是有重復///
for(tmp3=0;tmp3<=stage_num;tmp3++)/////tmp3標記現(xiàn)有的站點的數(shù)量
{
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;////一輛車的下行站點數(shù)
enable=0;
stage[tmp3].line_in++;
break;
}
}
//////////////////判斷重復結束///////////////////////
if(enable==1)////在查找的過程中如果沒有發(fā)現(xiàn)相同的則允許加入新的站點
{ ///**注意在新的站點加入的過程中,要將當前值紀錄進去**///
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;////一輛車的下行站點數(shù)
stage[stage_num].num=stage_num;
stage[stage_num].line_in=1;/////標記入棧的已經(jīng)有了一個
}
enable=1;/////為下一個站點的進入而準備
}
//test }
}
}
////////****站點錄入結束,已經(jīng)成功****///////////
void main(void)
{
int begin_stage=-1;/////起點站所在整個stage隊列數(shù)組中的位置
int end_stage=-1;////終點站在整個stage隊列數(shù)組中的位置
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;/////用于記錄不要轉車的交集個數(shù)
int same_counter1=0;/////用于記錄要轉一次車的交集個數(shù)
int same_counter2=0;/////用于記錄要轉兩次車的交集個數(shù)
int enable_add=1;/////看當前的車站點是不是可以加入
int cross_stage=0;///計算從起始站可以到達的站臺的集合
char line_all[1000][20];/////用于記錄從起點站出發(fā)所有可能到達站的集合
char line_num[500][20];/////存放line_all數(shù)組站臺所經(jīng)過的公交車的路數(shù)
int line_num_flag=0;/////已經(jīng)有多少公交車進入line_num數(shù)組
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數(shù)組,用于排序
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;/////用在模糊函數(shù)的處理中
int xiao0[100];///找到最大權值的ID(num),有可能存在相同的權值
int xiao0_counter=0;
int xiao1=0;////臨時的值,
int tishi=0;/////輸入乘車的選擇方案以便具體給出經(jīng)過哪些站點
int line_cmp_result;
cout<<" 功能菜單選項"<<endl;
cout<<endl;
cout<<" 0.退出"<<endl;
cout<<endl;
cout<<" 1.查詢某一條公交線的狀況"<<endl;
cout<<endl;
cout<<" 2.查詢經(jīng)過某一個站點的所有的公交線路"<<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<<"經(jīng)過的公交線為為"<<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 + -