L1-030. A bunch of one, L1-030.
"One-on-one learning group" is a common learning organization in primary and secondary schools. Teachers rank top-performing students and underperforming students in the same group. In this question, please write a program to help the teacher automatically complete the assignment, that is, after obtaining the rank of the class students, among the students not yet grouped, top-ranking students and top-ranking studentsOpposite SexStudents are divided into groups.
Input Format:
Enter a positive or even number of N (<= 50) in the first row, that is, the number of students in the class. In the next N rows, the gender of each student is given in the order of rankings from high to low (0 stands for girls and 1 stands for boys) and name (a non-empty string with no more than 8 English letters), separated by 1 space. Here, we ensure that the ratio of men to women in this class is and there is no parallel ranking.
Output Format:
Each row outputs the names of two students separated by one space. Top Students and low students. The output order of the group is arranged from high to low according to the ranking of the preceding students.
Input example:
80 Amy1 Tom1 Bill0 Cindy0 Maya1 John1 Jack0 Linda
Output example:
Amy JackTom LindaBill MayaCindy John
Time Limit: 400 ms memory limit: 65536 kB code length limit: 8000 B discriminant program Standard author Chen Yue's solution: Define a char-type array to store names, an array of int type is used to store gender (1 indicates male, 0 indicates female). The array of stored names is traversed from both sides. If two people have different gender, output these two names, mark the output person. Here, an array of the same size as the number of people is created, and Initialization is not 0. If the output is set to 1, until all the numbers in the array change to 1.
# Include <stdio. h> # include <stdlib. h> int main () {int n; int I, j; int sex [50]; char name [50] [20]; int arr [50] = {0 }; scanf ("% d", & n); if (n <0 | n> 50) exit (0); for (I = 0; I <n; I ++) {scanf ("% d", & sex [I]); scanf ("% s", name [I]) ;}for (I = 0; I <n; I ++) // traversing from the left {for (j = n-1; j> = 0; j --) // find the rightmost and composite person from the right. {if (arr [I] = 0 & arr [j] = 0 & sex [I]! = Sex [j]) // identifies the person that meets the criteria, which has not been output and has different genders {printf ("% s \ n", name [I], name [j]); arr [I] = 1; arr [j] = 1 ;}} return 0 ;}