当前位置:网站首页>L1-030 one gang one (15 points)

L1-030 one gang one (15 points)

2022-07-04 07:29:00 Inter personal liabilities^

L1-030 One gang, one (15 branch )

“ A group of students ” It is a common way of learning organization in primary and secondary schools , The teacher put the students who are in the first place and the students who are in the second place . Please write a program to help the teacher finish the assignment automatically , That is, after getting the ranking of the whole class , Among the students who are not currently grouped , Compare the top students with the bottom students opposite sex The students are divided into groups .

Input format :
Enter the first line to give a positive even number N(≤50), The number of students in the class . thereafter N That's ok , Give the gender of each student in the order of ranking from high to low (0 On behalf of girls ,1 On behalf of the boy ) And name ( No more than 8 A non empty string of English letters ), In the meantime 1 Space separation . It is guaranteed that the ratio of men to women in this class is 1:1, And there's no parallel .

Output format :
Output the names of two students in each line , In the meantime 1 Space separation . The high ranking students are in front , The students with lower rank are in the back . The output order of the group is from the top to the bottom according to the ranking of the students in front .

sample input :

8
0 Amy
1 Tom
1 Bill
0 Cindy
0 Maya
1 John
1 Jack
0 Linda

sample output :

Amy Jack
Tom Linda
Bill Maya
Cindy John

AC Code

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<sstream>

using namespace std;
typedef long long ll;
const int N=100010;

struct Student{
    
	int id;
	string name;
	bool flag;
}student[55];

int main()
{
    
	int n;
	cin >> n;
	for(int i = 0; i < n; i ++ )
		cin >> student[i].id >> student[i].name;
	for(int i = 0; i < n / 2; i ++ )
	{
    
		cout << student[i].name << ' ';
		for(int j = n - 1; j >= n / 2; j -- )
			if(student[i].id != student[j].id && student[j].flag != true)
			{
    
				cout << student[j].name << endl;
				student[j].flag = true;
				break;
			}
	}
	return 0;
}



原网站

版权声明
本文为[Inter personal liabilities^]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202141533227742.html