7-2 a bunch of one (15 points)

7-2 a bunch of one (15 points)

"A bunch of a study group," it is common in primary and secondary schools learning organization, teacher student academic performance by the front row of students with academic performance in a group. Heterosexual students this question, please you write a program to help teachers automate the distribution of work, that is, after getting the whole class rank, students not currently grouped in the ranking of the most forward of the rearmost ranking students and is divided into a group.

Input formats:

Input of the first row is given, i.e., a positive even number of the class N (≤50). Thereafter N rows, according to a descending order of rank is given to each student's gender (0 for female, 1 male representatives) and name (no more than 8 non-empty string of letters), separated by a space therebetween . This class men and women here to ensure that the ratio is 1: 1, and no dead heat.

Output formats:

Each line of output a set of two student's name, separated by a space between them. The former high-ranking students, low-ranking students in the post. In descending order of the output group arranged in front of the student's ranking.

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
n = int(input())
group = [
    [],
    [],
]
# [
#     ["Amy", "Cindy", "Maya", "Linda"],
#     ["Tom", "Bill", "John", "Jack"],
# ]
lst = []
for i in range(n):
    gender, name = input().split()
    lst.append((int(gender), name))
    group[int(gender)].append(name)

for i in range(n//2):
    gender = lst[i][0]
    t = group[gender][0]
    print(t, group[int(not gender)].pop())
    group[gender].remove(t)

Guess you like

Origin www.cnblogs.com/nobilis/p/11919806.html