Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 10. ** Student Groups
- At the Software University, we often organize programming courses for beginners in different towns. We usually run a registration form and after the registration finishes, we distribute the students into study groups. Groups have different sizes in each town.
- You are given a report holding the registrations for each town and the lab capacity (seats count) for each town. It comes in the following format:
- • Town name => X seats (where X is the capacity of the training lab in this town).
- o Student name | student email | registration date (in format day-month-year). The month name is given as 3 letters in English, e.g. “May”, “Aug” or “Nov”.
- o The next student come after the first, etc.
- • Then the next town and its students come, etc.
- • The input ends by a line holding “End”.
- The input comes in the following structure:
- Town1 => X seats
- Student1 Name | student1_email@somewhere.com | day-month-year
- Student2 Name | student2_email@somewhere.com | day-month-year
- Student3 Name | student3_email@somewhere.com | day-month-year
- …
- Town2 => X seats
- Student1 Name | student1_email@somewhere.com | day-month-year
- Student2 Name | student2_email@somewhere.com | day-month-year
- …
- End
- Your task is to create and print the study groups for each town as follows:
- • For each town create and print one or several study groups (depends of the number or registered students and the capacity of the lab in this town).
- • For each town order the students by registration date (ascending), then by name (ascending) then by email (ascending), then fill them into groups. If the students are less or equal to the lab capacity, create only one group. When the students are more than the lab capacity, distribute them in multiple groups.
- • Print all groups ordered by town (ascending) in the following format:
- o Created G groups and T towns:
- o Town1 => email1, email2, …
- o Town1 => email1, email2, …
- o …
- o Town2 => email1, email2, …
- o …
- Examples
- Input
- Plovdiv => 5 seats
- Ani Kirilova |ani88@abv.bg |27-May-2016
- Todor Nikolov | tod92@mente.org | 28-May-2016
- Kiril Stoyanov | kirtak@gmail.com | 27-May-2016
- Stefka Petrova | st96@abv.bg | 26-May-2016
- Ani Kirilova | ani.k@yahoo.co.uk | 27-May-2016
- Ivan Ivanov | ivan.i.ivanov@gmail.com| 27-May-2016
- Veliko Tarnovo => 3 seats
- Petya Stoyanova | stoyanova_p@abv.bg | 27-May-2016
- Stoyan Kirilov | 100yan@gmail.com | 24-May-2016
- Didi Miteva | miteva_d@yahoo.co.uk | 28-May-2016
- Kiril Nikolov | kiro@kiro.net | 25-May-2016
- Ivan Stefanov | ivan.stef86@gmail.com | 27-May-2016
- Maria Kirova | maria.k@abv.bg | 26-May-2016
- Varna => 2 seats
- Ivan Ivanov | ivan.ivanov96@gmail.com| 29-May-2016
- Stoyan Petrov | sto.sto.sto@gmail.com | 27-May-2016
- Ivan Ivanov | vankata@mail.bg | 1-Jun-2016
- Kiril Anev | anev_k@yahoo.co.uk | 27-May-2016
- Ivan Ivanov | vanyo98@abv.bg | 29-May-2016
- Petya Vladimirova|pete98@abv.bg | 20-May-2016
- Ivan Ivanov | ivan.94.ivan@gmail.com | 29-May-2016
- End
- Output
- Created 8 groups in 3 towns:
- Plovdiv => st96@abv.bg, ani.k@yahoo.co.uk, ani88@abv.bg, ivan.i.ivanov@gmail.com, kirtak@gmail.com
- Plovdiv => tod92@mente.org
- Varna => pete98@abv.bg, anev_k@yahoo.co.uk
- Varna => sto.sto.sto@gmail.com, ivan.94.ivan@gmail.com
- Varna => ivan.ivanov96@gmail.com, vanyo98@abv.bg
- Varna => vankata@mail.bg
- Veliko Tarnovo => 100yan@gmail.com, kiro@kiro.net, maria.k@abv.bg
- Veliko Tarnovo => ivan.stef86@gmail.com, stoyanova_p@abv.bg, miteva_d@yahoo.co.uk
- Comments
- Plovdiv (group 1 – 5/5 students)
- Stefka Petrova | st96@abv.bg | 26-May-2016
- Ani Kirilova | ani.k@yahoo.co.uk | 27-May-2016
- Ani Kirilova | ani88@abv.bg | 27-May-2016
- Ivan Ivanov | ivan.i.ivanov@gmail.com | 27-May-2016
- Kiril Stoyanov | kirtak@gmail.com | 27-May-2016
- Plovdiv (group 2 – 1/5 students)
- Todor Nikolov | tod92@mente.org | 28-May-2016
- Varna (group 1 – 2/2 students)
- Petya Vladimirova | pete98@abv.bg | 20-May-2016
- Kiril Anev | anev_k@yahoo.co.uk | 27-May-2016
- Varna (group 2 – 2/2 students)
- Stoyan Petrov | sto.sto.sto@gmail.com | 27-May-2016
- Ivan Ivanov | ivan.94.ivan@gmail.com | 29-May-2016
- Varna (group 3 – 2/2 students)
- Ivan Ivanov | ivan.ivanov96@gmail.com | 29-May-2016
- Ivan Ivanov | vanyo98@abv.bg | 29-May-2016
- Varna (group 4 – 1/2 students)
- Ivan Ivanov | vankata@mail.bg | 1-Jun-2016
- Veliko Tarnovo (group 1 – 3/3 students)
- Stoyan Kirilov | 100yan@gmail.com | 24-May-2016
- Kiril Nikolov | kiro@kiro.net | 25-May-2016
- Maria Kirova | maria.k@abv.bg | 26-May-2016
- Veliko Tarnovo (group 2 – 3/3 students)
- Ivan Stefanov | ivan.stef86@gmail.com | 27-May-2016
- Petya Stoyanova | stoyanova_p@abv.bg | 27-May-2016
- Didi Miteva | miteva_d@yahoo.co.uk | 28-May-2016
- Hints
- First, create the classes to hold the students, towns and groups.
- Creating Classes Student, Town and Group
- The class Student will hold the information about a student: name, email and date of registration.
- The class Town will hold the information about a town holding a list of registered students.
- The class Groups will hold the information about a group holding a subset of the students for certain town.
- Read the Input
- The next step is to read and parse the input to list of towns, each holding a list of students. Write a method to read the input from the console:
- In a loop, read a text line inputLine from the console, until “End” is reached.
- For each input line check whether the input line contains “=>”.
- • If yes inputLine holds a town, e.g. “Plovdiv => 5 seats”.
- o Create a new Town object.
- o Parse the town name and seats count from the input line and put them in the town.
- o Assign an empty student list for the new town:
- town.Students = new List<Student>().
- o Add the new town to the list of towns.
- • If no inputLine holds a student, e.g. “Ani Kirilova | ani.k@yahoo.co.uk | 27-May-2016”.
- o Create a new Student object.
- o Parse the student name, email and date from the input line and put them in the student.
- o Append the new student to the list of students for the last town in the towns list.
- Distribute the Students into Groups
- Now, solve the essential part of the problem: for each town, create one or several groups and distribute the students between them.
- Start from an empty method that takes as input a list of towns and produces as output a list of groups:
- How to distribute the students?
- In a loop go through the towns, sorted by name.
- • For each town order the students by registration date, name and email.
- • For each town put the first Town.SeatsCount students in the first group, the next Town.SeatsCount students in the second group, etc.
- You may use code like this or write it yourself:
- Print the Groups
- Once the students are distributed into groups, printing the output is the easiest part of this problem.
- • Print the total count of groups and total count of towns (distinct town names).
- • Loop through the groups, sorted by town name.
- • For each group print its name and the emails of its students, joined by “, ”.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement