L1-030. A bunch of one, L1-030.

Source: Internet
Author: User

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 ;}

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.