L1-030. One Gang One

"One-to-one study group" is a common learning organization method in primary and secondary schools. Teachers arrange students with high academic performance in a group with students with low academic performance. In this question, please write a program to help the teacher automatically complete this assignment, that is, after getting the ranking of the students in the whole class, among the students who have not yet been grouped, the students with the highest ranking and the students of the opposite sex with the lowest ranking are divided into one Group.

Input format:

The first line of input gives a positive even number N (<=50), the number of students in the class. Next N lines, give each student's gender (0 for female, 1 for male) and name (a non-empty string of no more than 8 English letters) of each student in descending order, separated by 1 space . It is guaranteed that the ratio of male to female in this class is 1:1, and there is no tie.

Output format:

Output a set of two student names per line, separated by 1 space. Students with higher rankings are in the front and students with lower rankings are in the back. The output order of the groups is arranged according to the rank of the previous students from high to low.

Input sample:
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

Code:

#include<stdio.h>
struct node
{
    int sex;
    int tag;
    char name[10];
}stud[100];
intmain()
{
    int i,j,n,m,k,t;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
       scanf("%d %s",&stud[i].sex,stud[i].name);
    }
    for(i=0;i<n/2;i++)
    {
        for(j=n-1;j>=n/2;j--)
        {
            if(stud[i].sex!=stud[j].sex&&stud[j].tag==0)
            {
                printf("%s %s\n",stud[i].name,stud[j].name);
                stud[j].tag=1;
                break;
            }
        }
    }
    return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325517515&siteId=291194637
one
ONE