Student information sorting

Source of the topic: http://116.56.140.75:8000/JudgeOnline/problem.php?id=1752

1752: Sorting of Student Information

Time Limit: 1 Sec Memory Limit: 64 MB

Topic description

There is a list of student information, and users need to sort them according to the information they need. Student information includes student number, name, class, department, and college.

enter

The first line has an integer n (1 <= n <= 10000), which indicates the number of pieces of student information, followed by n lines, each line contains 5 fields, namely: student number, name, class, department, College. After that, there is a line containing 2 integers b1 and b2, indicating that they are sorted according to the b1 or b2 fields respectively. This question does not have the same value in field 1 or field 2.

output

Output the result of each sorting. Separate the two outputs with a blank line.

sample input

10
200912341234 Chen Er Mathematics 09-2 School of Applied Mathematics and Science
200812341227 Chen San Mathematics 08-1 School of Applied Mathematics and Science
200912341269 Cai Erxin Engineering 09-1 School of Information Engineering and Information
200912341218 Li Si E-commerce 09-1 School of Electronic Commerce Information
200812341256 Wang Wuxin Engineering 08-2 School of Information Engineering and Information
200912341291 Zhao Liuxin Engineering 09-2 School of Information Engineering and Information
200812341234 Sun Qi Grass Industry 08-1 College of Grass Science and Agriculture
200912341268 Pig Eight Finance 09-1 Rural Finance and Economics Institute
200812341219 Laojiu Agricultural College 08-2 Agricultural College
200812341292 Liu Shi Project 08-2 Agricultural Machinery Engineering Institute
2 1

Sample output

200912341269 Cai Erxin Engineering 09-1 School of Information Engineering and Information
200912341234 Chen Er Mathematics 09-2 School of Applied Mathematics and Science
200812341227 Chen San Mathematics 08-1 School of Applied Mathematics and Science
200812341219 Laojiu Agricultural College 08-2 Agricultural College
200912341218 Li Si E-commerce 09-1 School of Electronic Commerce Information
200812341292 Liu Shi Project 08-2 Agricultural Machinery Engineering Institute
200812341234 Sun Qi Grass Industry 08-1 College of Grass Science and Agriculture
200812341256 Wang Wuxin Engineering 08-2 School of Information Engineering and Information
200912341291 Zhao Liuxin Engineering 09-2 School of Information Engineering and Information
200912341268 Pig Eight Finance 09-1 Rural Finance and Economics Institute

200812341219 Laojiu Agricultural College 08-2 Agricultural College
200812341227 Chen San Mathematics 08-1 School of Applied Mathematics and Science
200812341234 Sun Qi Grass Industry 08-1 College of Grass Science and Agriculture
200812341256 Wang Wuxin Engineering 08-2 School of Information Engineering and Information
200812341292 Liu Shi Project 08-2 Agricultural Machinery Engineering Institute
200912341218 Li Si E-commerce 09-1 School of Electronic Commerce Information
200912341234 Chen Er Mathematics 09-2 School of Applied Mathematics and Science
200912341268 Pig Eight Finance 09-1 Rural Finance and Economics Institute
200912341269 Cai Erxin Engineering 09-1 School of Information Engineering and Information
200912341291 Zhao Liuxin Engineering 09-2 School of Information Engineering and Information

Analysis: Just sort the members of the structure, pay attention to the sorting of the strings

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
struct
{
	string s1;
	string s2;
	string s3;
	string s4;
	string s5;
}node[10001];
string a[10001];
intmain()
{
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> node[i].s1 >> node[i].s2 >> node[i].s3 >> node[i].s4 >> node[i].s5;
	}
	int b[2];
	cin >> b[0] >> b[1] ;
	for (int i = 0; i < 2; i++)
	{
		if (b[i] == 1)
		{
			for (int j = 0; j < n; j++)
				a[j] = node[j].s1;
			sort(a, a + n);
			for (int j = 0; j < n; j++)
			{
				for (int k = 0; k<n; k++)
					if (node[k].s1 == a[j])
					{
						cout << node[k].s1 << " " << node[k].s2 << " " << node[k].s3
							<< " " << node[k].s4 << " " << node[k].s5 << endl;
						break;
					}
			}
		}
		else if (b[i] == 2)
		{
			for (int j = 0; j < n; j++)
				a[j] = node[j].s2;
			sort(a, a + n);
			for (int j = 0; j < n; j++)
			{
				for(int k=0;k<n;k++)
					if (node[k].s2 == a[j])
					{
						cout << node[k].s1 << " " << node[k].s2 << " " << node[k].s3
							<< " " << node[k].s4 << " " << node[k].s5 << endl;
						break;
					}
			}
		}
		else if (b[i] == 3)
		{
			for (int j = 0; j < n; j++)
				a[j] = node[j].s3;
			sort(a, a + n);
			for (int j = 0; j < n; j++)
			{
				for (int k = 0; k<n; k++)
					if (node[k].s3 == a[j])
					{
						cout << node[k].s1 << " " << node[k].s2 << " " << node[k].s3
							<< " " << node[k].s4 << " " << node[k].s5 << endl;
						break;
					}
			}
		}
		else if (b[i] == 4)
		{
			for (int j = 0; j < n; j++)
				a[j] = node[j].s4;
			sort(a, a + n);
			for (int j = 0; j < n; j++)
			{
				for (int k = 0; k<n; k++)
					if (node[k].s4 == a[j])
					{
						cout << node[k].s1 << " " << node[k].s2 << " " << node[k].s3
							<< " " << node[k].s4 << " " << node[k].s5 << endl;
						break;
					}
			}
		}
		else if (b[i] == 5)
		{
			for (int j = 0; j < n; j++)
				a[j] = node[j].s5;
			sort(a, a + n);
			for (int j = 0; j < n; j++)
			{
				for (int k = 0; k<n; k++)
					if (node[k].s5 == a[j])
					{
						cout << node[k].s1 << " " << node[k].s2 << " " << node[k].s3
							<< " " << node[k].s4 << " " << node[k].s5 << endl;
						break;
					}
			}
		}
		if (i == 0)
			cout << "\n";
	}
}

Code:

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324761929&siteId=291194637