C language data structure training - competition system

 

This code is a menu-style program that performs corresponding operations based on the options entered by the user. The following is the general process of code execution:

  1. Initialize the variable y to 1 and call the Read() function.
  2. Enter the while loop, the loop condition is that y is not equal to 0.
  3. Call the list() function to display the menu, and read the options entered by the user and store them in the variable x.
  4. Perform the corresponding operation according to the option x entered by the user:
    • If x equals 1, call the Insert() function.
    • If x equals 2, call the Delete() function.
    • If x equals 3, call the Exchange() function.
    • If x is equal to 4, you need to create an empty binary sort tree root, then loop through the array teams, and call the insertBST() function to insert each team into the binary sort tree root. Next, the user is required to enter the number of the participating team to be found, and then calls the Sreachnum() function to find the corresponding node in the binary sorting tree according to the number, and outputs the relevant information of the node. Additionally, ASL (Average Lookup Length) is calculated.
    • If x is equal to 5, the user is required to enter the participating school to be found, and then call the Searchsch() function to find the corresponding participating team according to the participating school and output relevant information.
    • If x is equal to 6, call the Call() function to implement a calling system.
    • If x is equal to 7, initialize an array view containing 11 attractions, and use the adjacency matrix adj to represent the distance between attractions. Then, the user is required to enter the starting point v and the end point v1, call the guidance() function to calculate the shortest path using Dijkstra's algorithm, and use the path array to save the path information. Finally, output the length and path of the shortest path.
  5. Prompt the user whether to continue the operation, read the user's choice and store it in the variable y.
  6. If the user chooses to continue (y is 1), return to step 2 to continue execution.
  7. If the user chooses to end (y is 0), the program ends.

It should be noted that some functions used in this code such as Read(), list(), Insert(), Delete(), Exchange(), insertBST(), Sreachnum(), countASL(), Searchsch(), Call (), guidance(), etc. are not given in the code. You can implement these functions by yourself to meet the needs of the program. In addition, you also need to pay attention to the scope of variables and functions to ensure that variables can be accessed in the correct location.

#include<iostream>
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include<string>
#include<sstream>
#include<fstream>
int const MaxSize = 11;	//最大顶点数
int const M = 9999;		//最大权值
int const Max = 500;
double ASL=0;		//平均查找长度
using namespace std;
 struct Team {
	 //参赛作品编号
	int number;
	//参赛作品名称
	string offering;
	//参赛学校
	string school;
	//赛事类别
	string category;
	//参赛者
	string name;
	//指导老师
	string teacher;
	//答辩时间
	int time;
}teams[Max];
Team s[Max],s1[Max];		//用一个数组存储查找出来的参赛队伍
struct BTree {
	//关键字值
	int number;
	//存储队伍基本信息
	Team* t;
	//结点的左右孩子指针
	BTree* lchild, * rchild;
};
struct View {
	//读取文件
	int id;				
	//景点名称
	string name;		
	//景点介绍
	string introduction;
}view[MaxSize];
int Count = 0;		//有多少个队伍
void Del_space(string& s) {    //去除字符串中的空格
	int index = 0;
	if (!s.empty()) {
	while ((index = s.find('\t', index)) != string::npos) { 
			s.erase(index, 1);
		}
	}
}
//读取文件
void Read() {
	ifstream file("team.txt");
	if (!file){
		cout << "打开文件失败" << endl;
	}
	string line;
	while (getline(file, line)) 
	{
		Team t;
		string s;
		Del_space(line);				//去除该行空格
		stringstream ss(line);
		//getline(ss, s, '#'); 			//实现字符串的输入,初始化ss
		getline(ss >> std::ws, s, '#');    //去除 cin 输入前面的空格,可以使用 std::ws 函数 
		getline(ss >> std::ws, t.offering, '#');
		getline(ss >> std::ws, t.school, '#');
		getline(ss >> std::ws, t.category, '#');
		getline(ss >> std::ws, t.name, '#');
		getline(ss >> std::ws, t.teacher, '#');
		t.number = atoi(s.c_str());	//将编号转化为整形,c_str()返回当前字符串的首字符地址,atoi (表示 ascii to integer)是把字符串转换成整型数的一个函数
		teams[Count] = t;
		Count++;
	}

	for (int i = 0; i < Count; i++)
		cout << "参赛队编号:" << teams[i].number 
		<< "参赛作品名称:" << teams[i].offering 
		<< "参赛学校:" << teams[i].school 
		<< "赛事类别:" << teams[i].category 
		<< "参赛者:" << teams[i].name 
		<< "指导老师:" << teams[i].teacher << endl;
	file.close();
	cout << "总共有 " << Count << " 个队伍" << endl;
}
//插入队伍
void Insert() {
	Team a;
	cout << "请输入添加队伍编号:";
	cin >> a.number;
	cout << "请输入添加队伍的作品名称:";
	cin >> a.offering;
	cout << "请输入添加队伍学校:";
	cin >> a.school;
	cout << "请输入添加队伍的赛事类别:";
	cin >> a.category;
	cout << "请输入添加参赛者:";
	cin >> a.name;
	cout << "请输入添加队伍指导老师:";
	cin >> a.teacher;
	teams[Count] = a;
	cout << "添加成功" << '\n';
	cout << "参赛队编号:" << teams[Count].number << "参赛作品名称:" << teams[Count].offering 
		<< "参赛学校:" << teams[Count].school << "赛事类别:" << teams[Count].category 
		<< "参赛者:" << teams[Count].name << "指导老师:" << teams[Count].teacher << endl;
	Count++;
 
}
//删除队伍
void Delete(){
	int num;
	cout << "请输入要删除的队伍编号:" << endl;
	cin >> num;
	for(int i=0;i<Count;i++){
		if (teams[i].number == num){
			cout << "删除队伍信息:" << endl;
			cout << "参赛队编号:" << teams[i].number << '\t' << "参赛作品名称:" << teams[i].offering<< '\t' 
				<< "参赛学校:" << teams[i].school << '\t' << "赛事类别:" << teams[i].category << '\t' 
				<< "参赛者:" << teams[i].name << '\t' << "指导老师:" << teams[i].teacher << endl;
			for (int j = i; j < Count; j++) {
				teams[j] = teams[j + 1];
		}
			Count--;
			cout << "删除成功" << endl;
			return;
		}
	}
	 	cout << "不存在此队伍" << endl;
}
//更改队伍信息
void Exchange() {
	int num;
	cout << "输入你要修改那个队伍的信息(输入编号):";
	cin >> num;
	for (int i = 0; i < Count; i++) {
		if (teams[i].number == num) {
			string s1,s2,s3,s4,s5;
			cout << "请输入更改后参赛作品名称:";
			cin >> s1;
			teams[i].offering = s1;
			cout << "请输入更改后队伍学校:";
			cin >> s2;
			teams[i].school = s2;
			cout << "请输入更改后的队伍的赛事类别:";
			cin >> s3;
			teams[i].category = s3;
			cout << "请输入更改后参赛者:";
			cin >> s4;
			teams[i].name = s4;
			cout << "请输入更改后队伍指导老师:";
			cin >> s5;
			teams[i].teacher = s5;
			break;
		}
	}
	cout << "修改成功" << endl;
}
//二叉树插入结点
BTree* insertBST(BTree* root, Team* team) {
	if (root == NULL) {	//当根结点为空时
		BTree* root1 = new BTree();
		root1->number = team->number;
		root1->t = team;
		root1->lchild = NULL;
		root1->rchild = NULL;
		return root1;
	}
	if (root->number < team->number) {		//当根结点的大小小于插入结点的大小
		root->rchild = insertBST(root->rchild, team);
	}
	else if (root->number > team->number){	
		root->lchild = insertBST(root->lchild, team);
	}
	return root;
}
//按编号搜索
BTree* Sreachnum(BTree* root, int number,int depth) {
	
	if (root == NULL)return NULL;
	if (root->number == number) {
		return root;
	}
	if (root->number < number) {
		return Sreachnum(root->rchild, number,depth+1);
	}
	else return Sreachnum(root->lchild, number,depth+1);
	if (root->number != number)return NULL;
}
//返回编号的深度,用来计算ASL
int countASL(BTree* root, int number, int depth) {
	if (root == NULL)return 0;
	if (root->number == number) {
		return depth;
	}
	if (root->number < number) {
		return countASL(root->rchild, number, depth + 1);
	}
	else return countASL(root->lchild, number, depth + 1);
	if (root->number != number)return 0;
}
//将相邻两个归并段合并成一个有序段的算法
void merge(int low, int mid, int high){
	int i = low, j = mid + 1, k = low;
	while (i <= mid && j <= high){
		if (s[i].number < s[j].number)
			s1[k++] = s[i++];
		else
			s1[k++] = s[j++];
	}
	while (i <= mid)
		s1[k++] = s[i++];
	while (j <= high)
		s1[k++] = s[j++];
	for (int i = low; i <= high; i++)
		s[i] = s1[i];
}
//归并排序算法总体部分
void mergesort(int x, int y){
	if (x >= y) return;
	int mid = (x + y) / 2;
	mergesort(x, mid);
	mergesort(mid + 1, y);
	merge(x, mid, y);
}
//按学校搜索
void Searchsch(string school) {	
	int j = 0;
	for (int i = 0; i < Max; i++) {
		if (teams[i].school == school) {
			s[j] = teams[i];
			j++;
		}
	}
	//归并排序
	mergesort(0, j-1);
	for (int i = 0; i < j; i++)
		cout << s[i].number <<'\t'<<s[i].offering <<'\t' << s[i].category <<'\t' << s[i].name <<'\t' << s[i].teacher <<'\n';
}
void Call() {
    //存放所有的参赛类型
    string type[4] = {"A", "B", "C", "D"};

    //存放决赛室名称
    string room[4] = {"A", "B", "C", "D"};

    //定义四个决赛室存放队伍的数组
    Team t[4][100];

    //自定义四种类型,将队伍分成四组
    for (int i = 0; i < 4; i++) {
        int k = 0;
        for (int j = 0; j < Count; j++) {
            if (type[i] == teams[j].category) {
                t[i][k] = teams[j];
                k++;
            }
        }
    }

    //模拟决赛室内叫号系统
    srand((unsigned int)time(NULL));
    for (int i = 0; i < 4; i++) {
        int hour = 8;
        int minute = 0;
        cout << "决赛室:" << room[i] << '\n';
        int j = 0;
        while (t[i][j].category != "") {
            t[i][j].time = rand() % (10 - 5 + 1) + 5;
            if (minute > 60) {
                hour++;
                minute -= 60;
            }
            cout << hour << ":" << minute << '\t' << t[i][j].offering << '\n';
            minute += t[i][j].time;
            j++;
        }
    }
}
void guidance(int a[][MaxSize],int dist[],int v,int path[]) {		//导航系统
	int k;
	int used[MaxSize];		//判断顶点是否被访问过
	for (int i = 0; i < MaxSize; i++) {
		if (i == v)used[v] = 1;
		else	used[i] = 0;		//初始化顶点的used都为0
	}
	for (int i = 0; i < MaxSize; i++) {		//初始化dist
		if (i == v)dist[i] = 0;				//v到自身的长度为0
		else
			dist[i] = a[v][i];			//将邻接矩阵中,v到各点的距离存放进去
		if (dist[i] < M)path[i] = v;	//当v到各地的距离不是oo时,将各点的前驱直接记成v
		else path[i] = -1;				//否则,记成-1
	}
	for (int i = 1; i < MaxSize; i++) {
		int min;
		min = 9999;
		for (int j = 0; j < MaxSize; j++) {
			if (j == v)continue;
			if (!used[j] && min > dist[j]) {		//当顶点未被访问且小于min时,将最短路径赋给min,并保存该顶点下标
				min = dist[j];
				k = j;
			}
		}
		used[k] = 1;		//将该顶点标为已被访问
		for (int j = 0; j < MaxSize; j++) {
			if (j == v)continue;
			if ((dist[k] + a[k][j]) < dist[j] && !used[j]) {		//当v到某个顶点的距离大于通过上述顶点中转到该点的距离时,修改dist值
				dist[j] = dist[k] + a[k][j];
				path[j] = k;		//将k设为j的前驱
			}
		}
	}
}
void find(int path[],int v,int v1) {	//输出路径
	int s;
	if (path[v1] == v) {		//当v1的前驱是v时,输出v
		cout << v;
	}
	else {			//当v1的前驱不是v时,递归调用,查找v的后继
		s = path[v1];	
		find(path,v,s); }
	cout << "->" << v1;
	return;
}
//目录
void list() {
	cout << "学生竞赛系统1.0" << '\n';
	cout << "请输入您的选择:(功能前的数字)" << '\n';
	cout << "1.添加队伍" << '\n';
	cout << "2.删除队伍" << '\n';
	cout << "3.修改队伍信息" << '\n';
	cout << "4.查找队伍" << '\n';
	cout << "5.按参赛学校查询参赛团队" << '\n';
	cout << "6.决赛叫号系统" << '\n';
	cout << "7.校园导航系统" << '\n';
}
int main() {
	int y = 1;
	Read();
	while (y != 0) {
		list();
		int x;
		cin >> x;
		if(x==1)Insert();
		if(x==2)Delete();
		if(x==3)Exchange();
		BTree* root = NULL;
		//创建二叉排序树
		for (int i = 0; i < Max; i++) {
			root = insertBST(root, &teams[i]);
		}
		if (x == 4) {
			cout << "输入要查找的参赛队编号:";
			int number1;
			cin >> number1;
			BTree* s = new BTree();
			s = Sreachnum(root, number1, 1);			//按编号查找
			if (s != NULL) {
				cout << "参赛作品名称:" << s->t->offering << '\t' << "参赛学校:" << s->t->school
					<< '\t' << "赛事类型:" << s->t->category << '\t' << "参赛者:"
					<< s->t->name << '\t' << "指导老师:" << s->t->teacher << endl;
 
				double s1 = 0;
				cout << "ASL=(";
				for (int i = 0; i < Count; i++) {
					int s2;
					s2 = countASL(root, teams[i].number, 1);
					s1 += s2;
					if (i == Count - 1)cout << s2 << ")*1/" << Count << " = ";
					else cout << s2 << "+";
				}
				ASL = s1 / Count;
				cout << ASL << '\n';
			}
			else cout << "查找失败!" << '\n';
		}
		if (x == 5) {
			cout << "输出要查找的参赛学校:";
			string Sea_school;
			cin >> Sea_school;
			Searchsch(Sea_school);				//按参赛学校查找参赛团队
		}
		if (x == 6) {
			cout << "叫号系统" << '\n';
			Call();						//叫号系统
		}
		if (x == 7) {
			cout << "校园导游系统" << '\n';
			for (int i = 0; i < 11; i++) {
				view[i].id = i;
			}
			view[0].name = "西区宿舍";
			view[0].introduction = "学生公寓区,有许多宿舍楼,是学生们休息、娱乐的地方,属于新建的宿舍楼,位于信阳农林学院西边,宿舍有空调、独立卫生间,二十四小时热水。";
			view[1].name = "学子食堂";
			view[1].introduction = "位于馨苑后边,有教工餐厅,有三层楼,菜品丰富、多样";
			view[2].name = "操场";
			view[2].introduction = "含有足球场,篮球场,排球场等。学生可以在这里踢足球、健身以及举办各种活动";
			view[3].name = "文体中心";
			view[3].introduction = "学校一餐三楼,可以举办晚会";
			view[4].name = "一号学楼";
			view[4].introduction = "公共教学大楼一号楼,是学生们上课学习的地方";
			view[5].name = "双创中心大楼";
			view[5].introduction = "信阳农林学院创新创业大楼,在行政楼对面";
			view[6].name = "图书馆";
			view[6].introduction = "是学校标志性建筑,图文咨讯中心,可以在这里自主学习,含有智能借还书系统";
			view[7].name = "新食堂";
			view[7].introduction = "学校新建的餐厅,位于三号教学楼旁边,菜品丰富、多样";
			view[8].name = "信息工程学院";
			view[8].introduction = "是计算机学院老师办公的地方,计算机专业的学生在这里进行实验和项目开发";
			view[9].name = "行政楼";
			view[9].introduction = "行政办公大楼,用于日常办公";
			view[10].name = "楚韵湖";
			view[10].introduction = "在这里可以看到学校最大的湖,景色很好,还有很多的天鹅(其实就是一群鸭子......),是打卡拍照的好去处";
			for (int i = 0; i < 11; i++) {
				cout << view[i].id << "、" << view[i].name << '\n';
			}
			//邻接矩阵
			int adj[][MaxSize] = { {0,200,M,450,M,M,M,M,M,M,M},	
				{200,0,200,300,M,M,M,M,M,M,M},
				{M,200,0,150,250,300,M,M,M,M,M},
				{450,300,150,0,M,M,M,550,M,M,M},
				{M,M,250,M,0,150,250,M,M,M,M},
				{M,M,300,M,150,0,300,M,300,M,M},
				{M,M,M,M,250,300,0,100,M,M,600},
				{M,M,M,550,M,M,100,0,M,M,M},
				{M,M,M,M,M,300,M,M,0,400,M},
				{M,M,M,M,M,M,M,M,400,0,300},
				{M,M,M,M,M,M,600,M,M,300,0} };
			//记录从v到v1的最短路径长度
			int dist[MaxSize] = { 0 };
			//图的前驱结点数组
			int path[MaxSize] = { 0 };
			cout << "输入起点:";
			int v;
			cin >> v;
			cout << "输入终点:";
			int v1;
			cin >> v1;
			cout <<view[v].name<< ":"<<view[v].introduction << '\n' <<view[v1].name<< ":" << view[v1].introduction << '\n';
			guidance(adj, dist, v, path);
			cout << "最短路径为:" << dist[v1] << '\n';
			cout << "路径:" << '\n';
			find(path, v, v1);
		}
		cout << '\n';
		cout << "是否继续操作(是输入1,否输入0)";
		cin >> y;
	}
	return 0;
}

 

Some global variables, structures and constants are defined, which together form the basic data structures and parameters of your program. Here is a summary of what I understand:

  1. Constant definition: You defined MaxSize to represent the maximum number of vertices, M to represent the maximum weight, and Max to represent a certain upper limit. These constants may be used in subsequent algorithms and data structures. used in.

  2. Global structure: You defined the Team structure to store the information of the participating teams, including number, title of work, school, event category, contestants, instructor and defense time . In addition, you also defined a BTree structure to represent the nodes of the binary sorting tree, including key values, basic team information, and left and right child pointers. In addition, you also define a View structure to represent the information of the attraction, including id, name and introduction.

  3. Global array: You define an array named teams to store the participating team information, and two auxiliary arrays s and s1 to store the found participating team information. In addition, you define an array named view to store attraction information.

  4. Global variables: You define Count to record the number of teams, and ASL to store the average search length.

Based on these basic data structures, you are likely to store, search, and process this information in subsequent code. Hope these global data structures are helpful to you.

int const MaxSize = 11;	//最大顶点数
int const M = 9999;		//最大权值
int const Max = 500;
double ASL=0;		//平均查找长度
using namespace std;
 struct Team {
	 //参赛作品编号
	int number;
	//参赛作品名称
	string offering;
	//参赛学校
	string school;
	//赛事类别
	string category;
	//参赛者
	string name;
	//指导老师
	string teacher;
	//答辩时间
	int time;
}teams[Max];
Team s[Max],s1[Max];		//用一个数组存储查找出来的参赛队伍
struct BTree {
	//关键字值
	int number;
	//存储队伍基本信息
	Team* t;
	//结点的左右孩子指针
	BTree* lchild, * rchild;
};
struct View {
	//读取文件
	int id;				
	//景点名称
	string name;		
	//景点介绍
	string introduction;
}view[MaxSize];
int Count = 0;		//有多少个队伍

This function seems to be used to remove spaces (including spaces, tabs, etc.) from strings. The function accepts a parameter s of type string and passes it by reference, so that the string passed in when calling the function can be directly modified.

The function first defines an integer variable index, and enters a while loop when the string s is not empty. In the loop, the find function of string is used to find the position of the next tab character in string s and assign its index to index. If a tab character is found, use the erase function to remove the tab character from the string, thus removing spaces.

It should be noted that this code can only remove tab characters (\t). If you need to remove other whitespace characters, you can make corresponding modifications in the function. In addition, this code does not process the spaces at the beginning and end of the string. If you need to remove the spaces at the beginning and end, you can use the string erase and find_first_not_of functions to achieve this.

void Del_space(string& s) {    //去除字符串中的空格
	int index = 0;
	if (!s.empty()) {
	while ((index = s.find('\t', index)) != string::npos) { 
			s.erase(index, 1);
		}
	}
}

 

This code is a function that reads files. The function is to read data from a file named "team.txt", parse each line of data into an instance of the Team structure, and then store it in a global array named teams. middle.

The following is the general flow of the code:

  1. First try to open the file named "team.txt" and perform error checking. If the file fails to be opened, an error message is output and the function exits.

  2. Then a string type variable line is defined to store each line of data read from the file.

  3. Then enter a while loop, use the getline function to read data from the file line by line, and then parse the data for each line.

  4. In the process of parsing each row of data, an instance t of Team type and a variable s of string type are first created to temporarily store the substrings separated from each row of data.

  5. Call the Del_space function to remove spaces from the current line.

  6. Use stringstream ss(line) to convert the current line of data into a string stream, and then use the getline function and stringstream to read each field with "#" as the delimiter one by one, and store it in the corresponding member of t.

  7. Convert the number s of string type into an integer and store it in the number member of t.

  8. Store t in the global teams array and increment the Count counter.

  9. After the loop ends, output the information of each participating team.

  10. Finally, close the file and output the total number of participating teams.

Generally speaking, the function of this code is to read the data in the file and parse it into structured information, and then perform some simple processing and output. It should be noted that this code does not handle in detail situations such as file opening failure and file format errors. You may need to conduct further error handling and robustness design based on the actual situation.

//读取文件
void Read() {
	ifstream file("team.txt");
	if (!file){
		cout << "打开文件失败" << endl;
	}
	string line;
	while (getline(file, line)) 
	{
		Team t;
		string s;
		Del_space(line);				//去除该行空格
		stringstream ss(line);
		//getline(ss, s, '#'); 			//实现字符串的输入,初始化ss
		getline(ss >> std::ws, s, '#');    //去除 cin 输入前面的空格,可以使用 std::ws 函数 
		getline(ss >> std::ws, t.offering, '#');
		getline(ss >> std::ws, t.school, '#');
		getline(ss >> std::ws, t.category, '#');
		getline(ss >> std::ws, t.name, '#');
		getline(ss >> std::ws, t.teacher, '#');
		t.number = atoi(s.c_str());	//将编号转化为整形,c_str()返回当前字符串的首字符地址,atoi (表示 ascii to integer)是把字符串转换成整型数的一个函数
		teams[Count] = t;
		Count++;
	}

	for (int i = 0; i < Count; i++)
		cout << "参赛队编号:" << teams[i].number 
		<< "参赛作品名称:" << teams[i].offering 
		<< "参赛学校:" << teams[i].school 
		<< "赛事类别:" << teams[i].category 
		<< "参赛者:" << teams[i].name 
		<< "指导老师:" << teams[i].teacher << endl;
	file.close();
	cout << "总共有 " << Count << " 个队伍" << endl;
}

 

This function implements the function of inserting new team information into the team array. The function uses an interactive method to sequentially require the user to enter the new team's number, title of work, school, event category, contestants, and instructor information. Next, insert the new team information into the teams array and update the number of teams Count. Finally, output the information of the inserted team and prompt that the insertion is successful.

This code implements a simple insertion function, but it should be noted that it can only handle the insertion operation of one team. If you need to insert in batches or provide a more flexible insertion method, you may need to further improve this function. In addition, the validity of user input (such as input format, boundary values, etc.) also needs to be verified and processed to ensure the robustness of the program.

//插入队伍
void Insert() {
	Team a;
	cout << "请输入添加队伍编号:";
	cin >> a.number;
	cout << "请输入添加队伍的作品名称:";
	cin >> a.offering;
	cout << "请输入添加队伍学校:";
	cin >> a.school;
	cout << "请输入添加队伍的赛事类别:";
	cin >> a.category;
	cout << "请输入添加参赛者:";
	cin >> a.name;
	cout << "请输入添加队伍指导老师:";
	cin >> a.teacher;
	teams[Count] = a;
	cout << "添加成功" << '\n';
	cout << "参赛队编号:" << teams[Count].number << "参赛作品名称:" << teams[Count].offering 
		<< "参赛学校:" << teams[Count].school << "赛事类别:" << teams[Count].category 
		<< "参赛者:" << teams[Count].name << "指导老师:" << teams[Count].teacher << endl;
	Count++;
 
}

 

This function implements the function of deleting team information based on the specified team number. First, the function requires the user to enter the team number to be deleted. Then, the function traverses the teams array to find team information that matches the input number. If matching team information is found, the detailed information of the team is output, the subsequent team information is moved forward by one position, and then the number of teams Count is updated. Finally, a prompt indicating successful deletion is given.

It should be noted that this code can only delete the first matching team information, but cannot delete duplicate team information or multiple team information. If there are multiple teams with the same number, the code may need to be further modified to implement more complex deletion logic. In addition, the validity of user input (such as input format, boundary values, etc.) also needs to be verified and processed to ensure the robustness of the program.

//删除队伍
void Delete(){
	int num;
	cout << "请输入要删除的队伍编号:" << endl;
	cin >> num;
	for(int i=0;i<Count;i++){
		if (teams[i].number == num){
			cout << "删除队伍信息:" << endl;
			cout << "参赛队编号:" << teams[i].number << '\t' << "参赛作品名称:" << teams[i].offering<< '\t' 
				<< "参赛学校:" << teams[i].school << '\t' << "赛事类别:" << teams[i].category << '\t' 
				<< "参赛者:" << teams[i].name << '\t' << "指导老师:" << teams[i].teacher << endl;
			for (int j = i; j < Count; j++) {
				teams[j] = teams[j + 1];
		}
			Count--;
			cout << "删除成功" << endl;
			return;
		}
	}
	 	cout << "不存在此队伍" << endl;
}

 

This function implements the function of changing team information based on the specified team number. First, the function requires the user to enter the team number whose information is to be modified. Then, the function traverses the teams array to find team information that matches the input number. If matching team information is found, the user is then asked to enter the new entry name, team school, event category, participant and instructor information, and then the corresponding team information is updated. Finally, a prompt is given indicating that the modification was successful.

This code implements a simple function of changing team information, but it should be noted that it can only modify the first matching team information, and cannot modify duplicate team information or multiple team information. If there are multiple teams with the same number, the code may need to be further modified to implement more complex change logic. In addition, the validity of user input (such as input format, boundary values, etc.) also needs to be verified and processed to ensure the robustness of the program.

//更改队伍信息
void Exchange() {
	int num;
	cout << "输入你要修改那个队伍的信息(输入编号):";
	cin >> num;
	for (int i = 0; i < Count; i++) {
		if (teams[i].number == num) {
			string s1,s2,s3,s4,s5;
			cout << "请输入更改后参赛作品名称:";
			cin >> s1;
			teams[i].offering = s1;
			cout << "请输入更改后队伍学校:";
			cin >> s2;
			teams[i].school = s2;
			cout << "请输入更改后的队伍的赛事类别:";
			cin >> s3;
			teams[i].category = s3;
			cout << "请输入更改后参赛者:";
			cin >> s4;
			teams[i].name = s4;
			cout << "请输入更改后队伍指导老师:";
			cin >> s5;
			teams[i].teacher = s5;
			break;
		}
	}
	cout << "修改成功" << endl;
}

This code implements the function of inserting new nodes into a binary search tree. Among them, Binary Search Tree (BST) is a special binary tree with the following properties:

  • For any node root, the values ​​of all nodes in its left subtree are less than the value of root.
  • For any node root, the values ​​of all nodes in its right subtree are greater than the value of root.
  • The left and right subtrees are both binary search trees.

In the function, first determine whether the root node is empty. If it is empty, create a new node as the root node and set the corresponding number and pointer information. If the root node is not empty, compare the number of the inserted node with the size of the root node:

  • If the number of the inserted node is greater than the number of the root node, the inserted node is placed into the right subtree (the insertBST function is called recursively).
  • If the number of the inserted node is less than the number of the root node, the inserted node is placed in the left subtree (the insertBST function is called recursively).

Finally, return the root node root. In this way, the recursive process will continue downward to find the correct position to insert the node and build a binary tree that satisfies the properties of a binary search tree.

It should be noted that this code only implements the function of inserting new nodes into the binary search tree. The specific binary tree data structure BTree and team information structure Team do not provide complete definitions and implementations. Therefore, if you want to apply this code to actual scenarios, you need to improve the team information structure and corresponding operation logic.

//二叉树插入结点
BTree* insertBST(BTree* root, Team* team) {
	if (root == NULL) {	//当根结点为空时
		BTree* root1 = new BTree();
		root1->number = team->number;
		root1->t = team;
		root1->lchild = NULL;
		root1->rchild = NULL;
		return root1;
	}
	if (root->number < team->number) {		//当根结点的大小小于插入结点的大小
		root->rchild = insertBST(root->rchild, team);
	}
	else if (root->number > team->number){	
		root->lchild = insertBST(root->lchild, team);
	}
	return root;
}

 

These two pieces of code implement the function of searching for nodes by number in a binary search tree and returning their depth.

The first piece of code is the search function Sreachnum, which receives the root node root of the binary search tree, the number to be searched, and the current depth depth as parameters. In the function, first determine whether the root node is empty, and return NULL if it is empty. Then determine the relationship between the number of the root node and the number to be searched:

  • If the number of the root node is equal to the number to be searched, the root node root is returned directly.
  • If the number of the root node is less than the number to be searched, the Sreachnum function is called recursively to search in the right subtree.
  • If the number of the root node is greater than the number to be searched, the Sreachnum function is called recursively to search in the left subtree.

It should be noted that in the code, the first if judgment is followed by two if-else statements, causing the last if-else to never be executed. Therefore, the last if-else statement can be deleted and only the return NULL in it is retained. statement.

The second piece of code is the function countASL that calculates ASL (Average Search Level, average search level). It also receives the root node root of the binary search tree, the number to be searched, and the current depth depth as parameters. In the function, first it is also determined whether the root node is empty, and if it is empty, 0 is returned. Then a similar recursive search process is performed, but the difference is that when the node corresponding to the number to be searched is found, the current depth depth is returned directly.

Combined, these two pieces of code can search for nodes by number in a binary search tree and calculate the depth of the searched node, which can be used to calculate ASL. However, it should be noted that in practical applications, the calculation of ASL needs to be analyzed and processed in order to improve the use and optimization of binary search trees.

//按编号搜索
BTree* Sreachnum(BTree* root, int number,int depth) {
	
	if (root == NULL)return NULL;
	if (root->number == number) {
		return root;
	}
	if (root->number < number) {
		return Sreachnum(root->rchild, number,depth+1);
	}
	else return Sreachnum(root->lchild, number,depth+1);
	if (root->number != number)return NULL;
}
//返回编号的深度,用来计算ASL
int countASL(BTree* root, int number, int depth) {
	if (root == NULL)return 0;
	if (root->number == number) {
		return depth;
	}
	if (root->number < number) {
		return countASL(root->rchild, number, depth + 1);
	}
	else return countASL(root->lchild, number, depth + 1);
	if (root->number != number)return 0;
}

This code implements the algorithm of merging two adjacent merge segments into an ordered segment.

In the function, the parameterlow represents the starting position of the merged segment, mid represents the dividing position of the merged segment, highIndicates the end position of the merged segment. This algorithm uses the idea of ​​​​merging sort and is divided into the following steps:

  1. Initialization variablesi, j and k are the starting positions of the merged sections.
  2. enters a loop wheni is less than or equal to mid and j is less than or equal to high, compare the sizes of s[i].number and s[j].number:
    • results[i].number小于s[j].number,Generals[i]returns1[k],并General ikEach person increases 1.
    • Good resultss[i].numberDayu etc.s[j].number,Generals[j]returns1[k],并GeneraljkEach person has 1.
  3. When the loop ends, there may be one merge segment that has been traversed, and another merge segment with remaining elements. Then use two while loops to copy the remaining elements into the s1 array.
  4. Finally, use a for loop to copy the elements from the s1 array back to the s array.

In this way, two adjacent merged segments are merged into one ordered segment by comparing and copying elements one by one.

It should be noted that in this code, there may be definition and initialization of s1 and s arrays. At the same time, it is also necessary to ensure that the merge segment range passed into the function is correct, and the elements in the array have attributes that can be compared and assigned.

//将相邻两个归并段合并成一个有序段的算法
void merge(int low, int mid, int high){
	int i = low, j = mid + 1, k = low;
	while (i <= mid && j <= high){
		if (s[i].number < s[j].number)
			s1[k++] = s[i++];
		else
			s1[k++] = s[j++];
	}
	while (i <= mid)
		s1[k++] = s[i++];
	while (j <= high)
		s1[k++] = s[j++];
	for (int i = low; i <= high; i++)
		s[i] = s1[i];
}

This code implements the overall part of the merge sort algorithm. Merge sort is a classic sorting algorithm that uses a divide-and-conquer strategy to recursively divide the array to be sorted into small sub-arrays, and then merge these sub-arrays until the entire array is sorted.

In the mergesort function of this algorithm, the parameter x represents the starting position of the merge sort, and the parameter y represents The end position of merge sort. First, judge the recursive base:

  • Ifx is greater than or equal to y, it means that the current array range is so small that there is only one element or no elements. There is no need to sort and return directly.
    Then, calculate the middle position mid and make recursive calls to the left and right halves respectively: mergesort: a>
  • Recursive callmergesort(x, mid) sorts the left half of the array.
  • Recursive callmergesort(mid + 1, y) sorts the right half of the array.
    Finally, call the merge function to merge the left and right parts into an ordered whole.

As a whole, this code continuously decomposes the array into smaller parts through recursion, and then merges these small parts into an ordered whole through the merge function. Thus the merge sort algorithm is implemented. It should be noted that in actual applications, the correctness of the array, boundary conditions and result processing need to be carefully considered and improved.

//归并排序算法总体部分
void mergesort(int x, int y){
	if (x >= y) return;
	int mid = (x + y) / 2;
	mergesort(x, mid);
	mergesort(mid + 1, y);
	merge(x, mid, y);
}

 

This code implements the function of searching by school name and outputting relevant information.

In the functionSearchsch, the parametersschool represent the name of the school to be searched. The function traverses the entire teams array to find records matching the school name and stores them in the s array.

First, the variablej is initialized to 0, which is used to record the position of the matching record in the s array. Then, traverse the entire array in a for loop: teams

  • If the school name of the current record is equal to the name of the school to be searched, copy the record to the s array and increment j by 1.

After completes the traversal, call the mergesort function to merge and sort the s array to ensure that the output results are sorted by number.

Finally, traverse the array through a for loop and output the relevant information of the matching records. s

It should be noted that in this code, the definition and initialization of the arrays are not given, and the correctness and initialization of the arrayteams are not given. Boundary conditions make default assumptions. In addition, relevant data structures and functions need to be designed and improved according to specific situations.

//按学校搜索
void Searchsch(string school) {	
	int j = 0;
	for (int i = 0; i < Max; i++) {
		if (teams[i].school == school) {
			s[j] = teams[i];
			j++;
		}
	}
	//归并排序
	mergesort(0, j-1);
	for (int i = 0; i < j; i++)
		cout << s[i].number <<'\t'<<s[i].offering <<'\t' << s[i].category <<'\t' << s[i].name <<'\t' << s[i].teacher <<'\n';
}

 

This code implements a simulated indoor calling system for the finals.

In the functionCall, we first define a string array to store the competition typetype and a string array to store the final room name room. Then, a two-dimensional arrayTeam t[4][100] is defined to store the teams in the four final rooms.

Next, through two nested for loops, the teams are grouped according to the participation type, and the teams that meet the type requirements are stored in the corresponding final room array.

Then, use the srand function and the current time as a seed to generate random numbers to simulate the team's time. Then, use a nested for loop to traverse the teams in each final room to simulate the process of the number calling system:

  • Initialize hourshour to 8 and minutesminute to 0.
  • Output the name of the current finals room.
  • Use variablesj to iterate the team array of each finals room. When the team's entry type is not empty, perform the following operations:
    • Generate random match timest[i][j].time.
    • If the number of minutes exceeds 60, add 1 to the number of hours and subtract 60 from the number of minutes.
    • Output the game time and team name information.
    • Add the number of minutes to the previously generated random match time.
    • jIncrement by 1 to perform the next round of calling operations.

Through the above steps, the function of the indoor call system for the finals is simulated. It should be noted that the teams array and Count variables in this code do not have specific definitions and initializations, so they need to be designed and improved according to needs in actual applications. related data structures and functions, and ensuring array correctness and boundary conditions. In addition, this code uses the time(NULL) function as the random number seed, so the header file <ctime> needs to be included.

void Call() {
    //存放所有的参赛类型
    string type[4] = {"A", "B", "C", "D"};

    //存放决赛室名称
    string room[4] = {"A", "B", "C", "D"};

    //定义四个决赛室存放队伍的数组
    Team t[4][100];

    //自定义四种类型,将队伍分成四组
    for (int i = 0; i < 4; i++) {
        int k = 0;
        for (int j = 0; j < Count; j++) {
            if (type[i] == teams[j].category) {
                t[i][k] = teams[j];
                k++;
            }
        }
    }

    //模拟决赛室内叫号系统
    srand((unsigned int)time(NULL));
    for (int i = 0; i < 4; i++) {
        int hour = 8;
        int minute = 0;
        cout << "决赛室:" << room[i] << '\n';
        int j = 0;
        while (t[i][j].category != "") {
            t[i][j].time = rand() % (10 - 5 + 1) + 5;
            if (minute > 60) {
                hour++;
                minute -= 60;
            }
            cout << hour << ":" << minute << '\t' << t[i][j].offering << '\n';
            minute += t[i][j].time;
            j++;
        }
    }
}

 

This code implements a navigation system that calculates the shortest path and path information from a source vertex to other vertices.

The parameters of functionguidance include adjacency matrixa, distance arraydist, and source vertexv and path arraypath.

First, an array is definedused to determine whether the vertex has been visited. Initialize the vertex's array through a for loop, and set the of the source vertex is 1, and the of the remaining vertices are set to 0. usedvusedused

Then, go through anotherfor loop to initialize the distance arraydist and the path arraypath.

  • If the current vertex indexi is equal to the source vertexv, set dist[i] to 0, indicating that the source vertex reaches The distance to itself is 0.
  • Otherwise, set dist[i] to the distance from the source vertex v to the vertex i in the adjacency matrix.
  • Ifdist[i] is less than a large value M (the specific value is not given here), set the path arraypath[i] as the source vertex. v, indicating that the source vertex reaches the vertex directlyi
  • Otherwise, set the path arraypath[i] to -1, indicating that the vertex i cannot be reached directly from the source vertex.

Next, two nested for loops are used to calculate the shortest path and update the path information.

  • The outer loop goes from 1 toMaxSize-1 (no specific value is given here), which means traversing all vertices except the source vertex.
  • The inner loop is used to select the vertex closest to the source vertex among the unvisited vertices, and record its index as k.
  • Mark selected verticesk as visited.
  • Traverse all unvisited vertices again through a nestedfor loop:
    • If the vertexj is equal to the source vertexv, continue the next loop.
    • If the sum of the distances from the vertexk to the vertexj is less than the distance from the source vertex to the vertexj, And the vertexj has not been visited, update the distance and path information of the vertexj.

Through the above steps, the shortest path and path information from the source vertex to other vertices are finally obtained, which are stored in the dist and path arrays respectively.

It should be noted that the specific numerical range and boundary conditions are not given in this code. Therefore, in actual applications, relevant data structures and functions need to be designed and improved according to requirements, and the adjacency matrix must be ensured a is correct and gives a reasonable M value. In addition, the maxSize constant is used in this code, but no specific value is given, which also needs to be defined according to the actual situation.

void guidance(int a[][MaxSize],int dist[],int v,int path[]) {		//导航系统
	int k;
	int used[MaxSize];		//判断顶点是否被访问过
	for (int i = 0; i < MaxSize; i++) {
		if (i == v)used[v] = 1;
		else	used[i] = 0;		//初始化顶点的used都为0
	}
	for (int i = 0; i < MaxSize; i++) {		//初始化dist
		if (i == v)dist[i] = 0;				//v到自身的长度为0
		else
			dist[i] = a[v][i];			//将邻接矩阵中,v到各点的距离存放进去
		if (dist[i] < M)path[i] = v;	//当v到各地的距离不是oo时,将各点的前驱直接记成v
		else path[i] = -1;				//否则,记成-1
	}
	for (int i = 1; i < MaxSize; i++) {
		int min;
		min = 9999;
		for (int j = 0; j < MaxSize; j++) {
			if (j == v)continue;
			if (!used[j] && min > dist[j]) {		//当顶点未被访问且小于min时,将最短路径赋给min,并保存该顶点下标
				min = dist[j];
				k = j;
			}
		}
		used[k] = 1;		//将该顶点标为已被访问
		for (int j = 0; j < MaxSize; j++) {
			if (j == v)continue;
			if ((dist[k] + a[k][j]) < dist[j] && !used[j]) {		//当v到某个顶点的距离大于通过上述顶点中转到该点的距离时,修改dist值
				dist[j] = dist[k] + a[k][j];
				path[j] = k;		//将k设为j的前驱
			}
		}
	}
}

 

This code implements the output of the shortest path from the source vertex to the target vertex.

The parameters of functionfind include path arraypath, source vertexv and target vertexv1.

First, a variables is defined to store the predecessor vertex of the target vertexv1.

Then, use a conditional judgment to determine how to output the path:

  • If the predecessor vertex of the target vertexv1 is the source vertexv, then the target vertexv1 is directly derived from the source vertex v is reachable, and the source vertex is output directly v.
  • Otherwise, it means that the target vertexv1 needs to be transferred through other vertices to reach it. Call the find function recursively to find the source vertex. vs

Finally, output->symbol and target vertexv1, representing the path from the source vertex to the target vertex.

It should be noted that the complete output statement is not given in this code, only the output logic of the path is given. In practical applications, corresponding output statements can be designed and improved according to needs. In addition, this code uses recursive calls to output paths, so in actual applications, you need to consider the output order and format of the paths, and ensure the correctness of the path arraypath and give reasonable source vertices. v and the target vertex v1.

void find(int path[],int v,int v1) {	//输出路径
	int s;
	if (path[v1] == v) {		//当v1的前驱是v时,输出v
		cout << v;
	}
	else {			//当v1的前驱不是v时,递归调用,查找v的后继
		s = path[v1];	
		find(path,v,s); }
	cout << "->" << v1;
	return;
}

This code defines a function namedlist, which is used to print out the directory or menu of a student competition system.

In this function, through a series of cout statements, the function list of the student competition system is printed in a specific format, including function numbers and corresponding function descriptions.

After users see this directory, they can select the corresponding function according to the number. This design allows users to clearly understand the functions provided by the system and quickly select the operations they need.

It should be noted that this only prints the directory and does not implement the actual function. The specific operations corresponding to each function need to be implemented in the corresponding function.

//目录
void list() {
	cout << "学生竞赛系统1.0" << '\n';
	cout << "请输入您的选择:(功能前的数字)" << '\n';
	cout << "1.添加队伍" << '\n';
	cout << "2.删除队伍" << '\n';
	cout << "3.修改队伍信息" << '\n';
	cout << "4.查找队伍" << '\n';
	cout << "5.按参赛学校查询参赛团队" << '\n';
	cout << "6.决赛叫号系统" << '\n';
	cout << "7.校园导航系统" << '\n';
}

 

This code is a main functionmain, which implements a student competition system that performs different functional operations according to user selection.

First, an integer variable is definedy, which is used to control whether to continue the operation. Read data by calling functionRead().

Then, through a loop, first call the functionlist() to display the system's function directory, and then perform the corresponding operations according to the user's selection.

According to the different numbers entered by the userx, perform the corresponding operations:

  • Ifx is equal to 1, call functionInsert() to add a team.
  • Ifx is equal to 2, call the functionDelete() to delete the team.
  • Ifx is equal to 3, call the functionExchange() to modify the team information.
  • Ifx is equal to 4, first create a binary sorting tree, then the user enters the team number to be foundnumber1, and calls the function Sreachnum Search the participating teams by number and output relevant information.
  • Ifx is equal to 5, the user enters the participating school to be foundSea_school, and calls the functionSearchsch to query by participating school Participating teams.
  • Ifx is equal to 6, call the functionCall() to implement the final calling system.
  • Ifx is equal to 7, first initialize an array containing campus location informationview[], then the user enters the starting point and end point and calls the functionto output the path. guidanceCalculate the shortest path and call the functionfind

After each operation, ask the user whether to continue the operation, and decide whether to continue executing the loop based on the user's inputy.

It should be noted that some functions are used in this code, such as Read(), Insert(), Delete(), < /span>, etc., which need to be determined according to Define and initialize according to actual conditions. , , , etc. need to be designed and improved according to needs in actual applications. These functions ensure the correctness of related data structures and algorithms. At the same time, some ungiven variables and constants are used in this code, such as , , Exchange(), Sreachnum()Searchsch()Call()MaxCountASL

int main() {
	int y = 1;
	Read();
	while (y != 0) {
		list();
		int x;
		cin >> x;
		if(x==1)Insert();
		if(x==2)Delete();
		if(x==3)Exchange();
		BTree* root = NULL;
		//创建二叉排序树
		for (int i = 0; i < Max; i++) {
			root = insertBST(root, &teams[i]);
		}
		if (x == 4) {
			cout << "输入要查找的参赛队编号:";
			int number1;
			cin >> number1;
			BTree* s = new BTree();
			s = Sreachnum(root, number1, 1);			//按编号查找
			if (s != NULL) {
				cout << "参赛作品名称:" << s->t->offering << '\t' << "参赛学校:" << s->t->school
					<< '\t' << "赛事类型:" << s->t->category << '\t' << "参赛者:"
					<< s->t->name << '\t' << "指导老师:" << s->t->teacher << endl;
 
				double s1 = 0;
				cout << "ASL=(";
				for (int i = 0; i < Count; i++) {
					int s2;
					s2 = countASL(root, teams[i].number, 1);
					s1 += s2;
					if (i == Count - 1)cout << s2 << ")*1/" << Count << " = ";
					else cout << s2 << "+";
				}
				ASL = s1 / Count;
				cout << ASL << '\n';
			}
			else cout << "查找失败!" << '\n';
		}
		if (x == 5) {
			cout << "输出要查找的参赛学校:";
			string Sea_school;
			cin >> Sea_school;
			Searchsch(Sea_school);				//按参赛学校查找参赛团队
		}
		if (x == 6) {
			cout << "叫号系统" << '\n';
			Call();						//叫号系统
		}
		if (x == 7) {
			cout << "校园导游系统" << '\n';
			for (int i = 0; i < 11; i++) {
				view[i].id = i;
			}
			view[0].name = "西区宿舍";
			view[0].introduction = "学生公寓区,有许多宿舍楼,是学生们休息、娱乐的地方,属于新建的宿舍楼,位于信阳农林学院西边,宿舍有空调、独立卫生间,二十四小时热水。";
			view[1].name = "学子食堂";
			view[1].introduction = "位于馨苑后边,有教工餐厅,有三层楼,菜品丰富、多样";
			view[2].name = "操场";
			view[2].introduction = "含有足球场,篮球场,排球场等。学生可以在这里踢足球、健身以及举办各种活动";
			view[3].name = "文体中心";
			view[3].introduction = "学校一餐三楼,可以举办晚会";
			view[4].name = "一号学楼";
			view[4].introduction = "公共教学大楼一号楼,是学生们上课学习的地方";
			view[5].name = "双创中心大楼";
			view[5].introduction = "信阳农林学院创新创业大楼,在行政楼对面";
			view[6].name = "图书馆";
			view[6].introduction = "是学校标志性建筑,图文咨讯中心,可以在这里自主学习,含有智能借还书系统";
			view[7].name = "新食堂";
			view[7].introduction = "学校新建的餐厅,位于三号教学楼旁边,菜品丰富、多样";
			view[8].name = "信息工程学院";
			view[8].introduction = "是计算机学院老师办公的地方,计算机专业的学生在这里进行实验和项目开发";
			view[9].name = "行政楼";
			view[9].introduction = "行政办公大楼,用于日常办公";
			view[10].name = "楚韵湖";
			view[10].introduction = "在这里可以看到学校最大的湖,景色很好,还有很多的天鹅(其实就是一群鸭子......),是打卡拍照的好去处";
			for (int i = 0; i < 11; i++) {
				cout << view[i].id << "、" << view[i].name << '\n';
			}
			//邻接矩阵
			int adj[][MaxSize] = { {0,200,M,450,M,M,M,M,M,M,M},	
				{200,0,200,300,M,M,M,M,M,M,M},
				{M,200,0,150,250,300,M,M,M,M,M},
				{450,300,150,0,M,M,M,550,M,M,M},
				{M,M,250,M,0,150,250,M,M,M,M},
				{M,M,300,M,150,0,300,M,300,M,M},
				{M,M,M,M,250,300,0,100,M,M,600},
				{M,M,M,550,M,M,100,0,M,M,M},
				{M,M,M,M,M,300,M,M,0,400,M},
				{M,M,M,M,M,M,M,M,400,0,300},
				{M,M,M,M,M,M,600,M,M,300,0} };
			//记录从v到v1的最短路径长度
			int dist[MaxSize] = { 0 };
			//图的前驱结点数组
			int path[MaxSize] = { 0 };
			cout << "输入起点:";
			int v;
			cin >> v;
			cout << "输入终点:";
			int v1;
			cin >> v1;
			cout <<view[v].name<< ":"<<view[v].introduction << '\n' <<view[v1].name<< ":" << view[v1].introduction << '\n';
			guidance(adj, dist, v, path);
			cout << "最短路径为:" << dist[v1] << '\n';
			cout << "路径:" << '\n';
			find(path, v, v1);
		}
		cout << '\n';
		cout << "是否继续操作(是输入1,否输入0)";
		cin >> y;
	}
	return 0;
}

Guess you like

Origin blog.csdn.net/weixin_66547608/article/details/135038973