⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 new_file.cpp

📁 本程序实现的是南京的公交线路查询
💻 CPP
📖 第 1 页 / 共 5 页
字号:

#include<iostream.h>
#include<fstream.h>
#include<string.h>
#include<math.h>
///* change 是用于转一次车的情况  *///
struct change/////标记中转一次时由起点到终点的所有属性
{
	char round[20];////中转点名称
	char begin_line[20];////起始到中转点要坐的车号
	int begin_id;/////起点到中转的id号
	char end_line[20];///记录中转到终点的车号
	int end_id;////中转到终点的id号
	int lu_cheng;/////要经过的路程数
	
};

struct two_to_out
{
	int my_id;////记录实现起点到终点的方案的ID号

	char begin_to_zhongzhuan1[20];/////起点到中转1所要经过的公交路线
//	int begin_to_zhongzhuan1_id;/////起点到中转1所要经过的公交路线的ID号
	int begin_to_zhongzhuan1_begin_num;/////在起点到中转1的公交线路中,起点站在这个公交线路中的位置
	int begin_to_zhongzhuan1_end_num;/////在起点到中转1的公交线路中,中转1在这个公交线路中的位置
//	char begin_to_zhongzhuan1_stage[50][20];//////起点到中转线路所要经过的公交站点的名字
	int begin_to_zhongzhuan1_stage_flag;/////记录实际上从起点到中转1有多少公交站台
	
	char zhongzhuan1_to_zhongzhuan2[20];/////中转1到中转2的公交路线
//	int zhongzhuan1_to_zhongzhuan2_id;//////中转1到中转2的公交路线的ID号
	int zhongzhuan1_to_zhongzhuan2_begin_num;/////在中转1到中转2的路线中,中转1在整个中间路线中的位置
	int zhongzhuan1_to_zhongzhuan2_end_num;/////在中转1到中转2的路线中,中转2在整个公交线路中的位置
//	char zhongzhuan1_to_zhongzhuan2_stage[50][20];////中转1到中转2所要经过的站点的名字
	int zhongzhuan1_to_zhongzhuan2_stage_flag;/////中转1到中转2实际上要经过的站点的数目
	
	char zhongzhuan2_to_end[20];////中转2到终点的公交路线的名字	
//	int zhongzhuan2_to_end_id;/////中转2到终点的公交路线的ID号
	int zhongzhuan2_to_end_begin_num;////在中转2到终点的公交路线中,中转2所处的位置
	int zhongzhuan2_to_end_end_num;////在中转2到终点的公交路线中,终点所处的位置
//	char zhongzhuan2_to_end_stage[50][20];/////中转2到终点所经过的公交站点的名字
	int zhongzhuan2_to_end_stage_flag;//////中转2到终点实际上经过的站点的数目
	
	char zhongzhuan1_stage[20];///////中转1的站台名字
		
	char zhongzhuan2_stage[20];/////中转2的展台名字
	
	int begin_to_end_distance;/////起点到终点所要经过的站台总数目
	
};


two_to_out final_out[600];///////用于最后的数据的输出,存放的是起点到终点需要转两次车的所有方案,假设最多两百种
int final_out_flag=0;/////记录实际上输出的方案的数目,和上面的数组是相对应的


////***以下的结构体的定义是为了转车两次的情况服务**///
struct station_change_bus
{
	int change_line_num;//////记录从起点或终点到站台change_round[20]的所有可能的公交路线的数量
	char change_line_name[30][20];/////由起点或终点到中转的公交路线名字/*和下面的change_line_id 是一一对应的*/
	int change_line_id[30];////由起点或者终点到中转的公交路线ID号	   /*和上面的change_line_name 是一一对应的*/
	char change_round[20];////中转站的名字
	
	int qidian_stage_num[30];////起点在当前公交线路中的位置,即num    /*和上面的一一对应,由于同一个起点或终点站在不同的公交线路中所对应的站号也不同*/
	int zhongdian_stage_num[30];//////中转1在当前公交线路中的位置   /*和上面的相对应,由于同一个中转在不同的公交线路中所对应的站号不同*/


	int change_round_id;////对应于上面的中转站的ID号
	int distance[20];////由到中转所要的距离								/*和上面的相对应*/
};

///*  change_twice 是用于转两次车的情况  *///
struct change_twice
{
	int my_id;////记录在转两次的线路选择中的id号,通过输入id号就可以得到转两次车的乘车方案
	
	station_change_bus begin_to_change1[500];//////假设从起点到中转1的方案总数至多为500个,此时中转1的站台还没有确定
	int begin_to_change1_flag;////标记实际上从起点到中转1的方案数目,初始值为0
	
	char change_line2[20];////由第一道中转站到第二道中转所要的公交路线的名字,为最早得到的值
	int change_id2;/////第一道中转到第二段中转的公交车的ID号,即change_line2[20]的id号
	
	station_change_bus end_to_change2[500];///////从终点到中转2的方案,至多为500个,此时中转2的站台还没确定
	int end_to_change2_flag;////标记实际上从终点到中转2的方案数目,初始值为0
	
	int lu_cheng[500];/////总共要经过的站台的数目
	
};
change_twice change_two[600];///// 支持最多的转两路车的情况有六百种方案
int change_two_flag=0;/////标记实际的中转路线的条数
struct together
{
	char way[20];////标记是哪一路车
	int num;////标记着一路车在整个路线的位置
};

char input1[20];////
char input2[20];////两个字符数组,用于存放两个输入的字符

struct station
{
	char name[20];////站点的名字
	together biaoji[100];///包括车号和站点的排序
	int num;////标记已经有了多少个站台库,相当于ID号
	int line_in;////标记有了多少条线路入栈
	int quan;/////比较在模糊算法中的比较权值
	//	int way[100];////经过站点的车的车号
	//	int biaoji[200];////biaoji数组的作用是标明当前站台是某一条公交线的正向第几站
	//	station *next;///指向下一个站点
};

struct bus
{
	
	char name[20];////公交车的车号
	char line[100][20];///////记录这一条公交线所经过的车站的名字
	int geshu;////记录这一条线共有多少条站
	int id;/////用于记录本站在bus_line数组中的标号
	
};
station stage[3000];
bus bus_line[600];
int stage_num=0;////record tmpe stage
int bus_num=0;///record temp bus

///*以下函数的作用是根据输入的公交线路的名字来确定此公交线路的id号*///
int return_bus_id(char *p)
{
	for(int light0=0;light0<=bus_num;light0++)
	{
		int tmp_light1;
		tmp_light1=strcmp(bus_line[light0].name,p);
		if(tmp_light1==0)
		{
			return bus_line[light0].id;
			
		}
		
	}
}

///** 以下函数的作用是根据输入的站台的名字来返回站台的ID号    **///
int return_stage_id(char *p)
{

	for(int tmp_use=0;tmp_use<=stage_num;tmp_use++)////遍历所有的站点
	{
		int tmp_me;
		tmp_me=strcmp(stage[tmp_use].name,p);
		if(tmp_me==0)
		{
		
		return stage[tmp_use].num;///////返回ID号
		
		}
	
	
	}
	return -1;
}

///***以下函数的作用是根据一条公交线路中的起始位置和终了位置,输出处于期间的公交站点的名字**////
void output_stage_with_line(int start_num,int end_num,int bus_in_id)
{	
	if(start_num>end_num)/////如果起始的站牌号大于终了的站牌号
	{
		int out_enter_here=0;

		for(int wjs0=start_num;wjs0>=end_num;wjs0--)
		{
			out_enter_here++;
			if(out_enter_here%6==0)cout<<endl;///每6个站点一行输出一个回车
			cout<<bus_line[bus_in_id].line[wjs0]<<" ->";
		}		
		
	}
	else/////如果起始的站牌号小于终了站点的站牌号
	{
		int out_enter_here1=0;
		for(int wjs1=start_num;wjs1<=end_num;wjs1++)
		{
			out_enter_here1++;
			if(out_enter_here1%6==0)cout<<endl;/////每六个站点输出一个回车
			cout<<bus_line[bus_in_id].line[wjs1]<<"-> ";			
		}		
	}	
}

//////////***函数的作用是产生字符串比较的权值,看他们的相似程度***////////////
int mohu(char *mohu_in,char *have)
{
	
	int tmp_num=0;
	int ret_num=0;
	int max;////数组中长度比较长的那一个的长度
	int min;////数组中长度比较短的那一个
	if(strlen(mohu_in)>=strlen(have))
	{
		
		max=strlen(mohu_in);
		min=strlen(have);
		
	}
	else
	{
		
		max=strlen(have);
		min=strlen(mohu_in);
		
		
	}
	
	for(int wife0=0;wife0<=(max-min);wife0++)////总共要比较的次数
	{
		for(int wife1=0;wife1<min;wife1++)///对于每一次比较而言所要比较的字符的数目
		{
			if(strlen(mohu_in)>=strlen(have))//////字符char0的长度大于字符串char1的情况
			{
				
				if(have[wife1]==mohu_in[wife1+wife0])
					tmp_num++;
				
			}
			else
			{
				if(mohu_in[wife1]==have[wife1+wife0])
					tmp_num++;				
			}
			
		}
		if(tmp_num>=ret_num)
			ret_num=tmp_num;
		tmp_num=0;
		
	}
	return ret_num;
	
}
///////////////////////****以上函数是模糊搜索要用到的函数*****///////////////////////////

////////****下面函数的作用是建立stage结构体和bus结构体*****////////////
void read_file(void)
{
	char ch;
	int tmp1=0;////用于记录站牌的数字
	int tmp2=0;////用于记录在一条公交线上的站牌数量
	int tmp3=0;////用于记录一个站牌的字符到了第几个
	int enable_add_line=1;////允许现在是加入到公交线路中
	
	ifstream infile;
	infile.open("公交线路.txt");
	
	while(infile>>ch)
	{	
		
		if(ch==' ')continue;/////不考虑空格在其中的作用
		if(ch==':')///////当遇到':'时表示公交线路名字的输入结束,把输入字符只当作字符来看
		{
			enable_add_line=0;
			continue;
		}
		
		if(enable_add_line==1)
		{
			bus_line[bus_num].name[tmp1]=ch;
			tmp1++;
			//		if(tmp1==3)tmp1=0;
			//////****首先得到站牌的号码***/////
		}
		else
		{
			
			if(ch==',')////tmp2记录在每一条线上的站点
			{
				tmp2++;
				tmp3=0;
			}
			else
			{
				if(ch==';')
				{
					enable_add_line=1;//////当遇到';'时表示一条公交线路的录入结束了,允许加入到公交线的名字
					bus_line[bus_num].id=bus_num;
					
					//曹金灿改	bus_line[bus_num].num=convert(bus_line[bus_num].name);
					bus_line[bus_num].geshu=tmp2;
					bus_num++;////;为每一条线路的结束标志
					
					tmp1=0;
					tmp2=0;
					tmp3=0;
					///////***重新初始化等待下一次**//////
				}
				else
				{
					bus_line[bus_num].line[tmp2][tmp3]=ch;
					//		cout<<tmp2;
					tmp3++;
				}
				
			}
			
			
			
			

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -