TopcoderArchive
Archive
Algorithm problem

StudentsSet

Problem statement, definition, constraints, and public examples.

Problem Statement

Write a utility to sort students based on their characteristics.

Given class StudentsUtils:

Contains various methods to solve this problem.

class StudentsUtils {
  /**
   *  Creates a StudentsUtils object corresponding to the given data seed.
   * 
   *  @param dataSeed is an integer between 0 and 10^9, inclusive.
   */
  public StudentsUtils(int dataSeed);

  /**
   *  Returns the set of students to sort. All students in the set will have distinct names and IDs.
   * 
   *  @return Set containing between 1 and 10,000 students, inclusive.
   */
  public Set<Student> getStudentsSet();

  /**
   *  Gets the array containing IDs of various students. This array is sorted in
   *  ascending order and must have IDs of all students from getStudentsSet().
   *  All IDs in the array are distinct.
   * 
   *  @return Array containing between 1 and 1,000,000 integers, inclusive, where each
   *          integer is between 0 and 10^9, inclusive.
   */
  public int[] getStudentsIds();

  /**
   *  Gets the array containing the same number of elements as getStudentsIds(). The i-th
   *  element of this array denotes marks corresponding to subject 1 of the student with the ID given
   *  in the i-th element of array getStudentsIds().
   *
   *  @return Array containing between 1 and 1,000,000 integers, inclusive, where each
   *          integer is between 0 and 10, inclusive.
   */
  public int[] getStudentsMarks1();

  /**
   *  Gets the mapping of students to their marks for subject 2. The set of keys
   *  in this map contains exactly the same students as getStudentsSet().
   * 
   *  @return A Map<Student, Integer> where the value for each key is an integer
   *          between 0 and 10, inclusive.
   */
  public Map<Student, Integer> getStudentsMarks2();

  /**
   *  Gets the check sum for the given SortedSet<Student>. This checksum depends
   *  on the contents of the set and the order of students.
   *
   *  @param students is a sorted set containing students.
   *  @return the checksum for the given sorted set of students.
   */
  int checkStudentsOrder(SortedSet<Student> students);
}

Given class Student:

Describes a single student. Each student has a unique identifier, grade and name. For some students, you can also get their marks for two fixed subjects by using the methods of class StudentsUtils.

class Student {
  /**
   *  Get the unique identifier for this student.
   * 
   *  @return Identifier between 0 and 10^9 inclusive.
   */
  int getId();

  /**
   *  Gets the grade for this student.
   * 
   *  @return Grade between 0 and 10, inclusive.
   */
  int getGrade();

  /**
   *  Gets the name of this student.
   * 
   *  @return String containing between 1 and 20 letters ('a'-'z', 'A'-'Z'), inclusive.
   */
  String getName();
}

DEFINITION

You must define a public class StudentsSet with public method int orderStudents(int dataSeed).

Implement orderStudents as follows:

Create StudentsUtils stUtils by passing dataSeed to StudentsUtils(int). Obtain the set of students to sort using stUtils.getStudentsSet(). Get the marks for subjects 1 and 2 for all students in this set. Then, sort all the students according to the following rules:

  1. If two students A and B have distinct grades, the student with the smaller grade is lower than the other student. Otherwise, go to step 2.
  2. If two students A and B have distinct marks for the subject 1, the student with the lesser marks is lower than the other student. Otherwise, go to step 3.
  3. If two students A and B have distinct marks for the subject 2, the student with the lesser marks is lower than the other student. Otherwise, go to step 4.
  4. The student with alphabetically smaller name is lower than the other student.

Create a SortedSet<Student> containing all the students from getStudentsSet() sorted in the described order. Pass this sorted set to checkStudentsOrder() and return the resulting integer.

Definition

Class:
StudentsSet
Method:
orderStudents
Parameters:
int
Returns:
int
Method signature:
int orderStudents(int dataSeed)
(be sure your method is public)

Constraints

  • dataSeed will be between 0 and 1,000,000,000, inclusive.

Examples

  1. 1
    Returns: -1293409074
    There is only one student.
  2. 2
    Returns: 234665529
    There are three students and they have to be sorted in the following order: 1. Name = JMhHjinQciIUEfsm, grade = 7, mark1 = 2, mark2 = 3. 2. Name = LZiLryNNht, grade = 8, mark1 = 0, mark2 = 3. 3. Name = BWMhJduhKkwPHhkz, grade = 8, mark1 = 4, mark2 = 1.
  3. 3
    Returns: -932650593
    There are 10 students and they have to be sorted in the following order: 1. Name = IqdrLJPKqINosVBypFB, grade = 0, mark1 = 3, mark2 = 6. 2. Name = feSWFGpeMOBmFM, grade = 1, mark1 = 1, mark2 = 1. 3. Name = esmBayWJa, grade = 1, mark1 = 3, mark2 = 2. 4. Name = mSDKYGQhEjujSpS, grade = 1, mark1 = 10, mark2 = 3. 5. Name = TZf, grade = 2, mark1 = 9, mark2 = 0. 6. Name = zxiu, grade = 4, mark1 = 3, mark2 = 0. 7. Name = SGzGcRqvcW, grade = 4, mark1 = 7, mark2 = 1. 8. Name = yAyX, grade = 4, mark1 = 9, mark2 = 5. 9. Name = OAeCcOiONqCHfAal, grade = 5, mark1 = 10, mark2 = 0. 10. Name = WdgkhAkB, grade = 10, mark1 = 1, mark2 = 7.
  4. 4
    Returns: -1674048411
    There are 100 students.
  5. 5
    Returns: -202081836
    There are 1000 students.
Back to all problems