Professional Documents
Culture Documents
Week 12
Week 12
Week 12
Shpresa Fondation collects money from its donors. And then it distributes the collected money to the people
who need. The money is collected directly from people or people donates through different banks. This year,
they want to present certificates to their Top N Donors and thus they need to put the donors in descending
order according to their total donation.
Question:
Write a program that is going to read m donors' name surname and the amount donated, and then the
program is going to list top n donors in descending order.
Note: Pay attention for the worst case running time.
Input specification
You will be first given 2 integer numbers: The number of donors (m) and the number of (n) top donors to be
listed where 1 ≤ m ≤ 10,000 and 1 ≤ n ≤ 1000. Then the following m lines will give m donors names and
surnames and amount of donation. Every name and surname contains at most 12 characters. And
amountDonated can be floating point number between 0 and 10 6
Output specification
Show name surname and amountDonated of top n people in descending order.
Your math professor keeps student grades in a file. Time to time, he wants to see student lists sorted
according to averages.
Question:
Write a program that reads student names surnames and 4 marks for every student. Then, your program will
show top m students sorted in descending order according to the averages.
Input specification
The first line of the input contains two integers (n and m) where n denotes the number of students and m
denotes the number of top students to show in the output where 1 ≤ m ≤ n ≤ 600. Each of the following n
lines will have:
Output specification
Show top m students' names surnames and averages (with 2 decimal places after the floating point).
Question: The library is moving to the new facility. At the same time, the administration wants to record the
books to the new library program system. They bring bunch of books all the time and put them to the
registration office desk. The registration officer, takes the books one by one and registers them to the system
(remove from the stack). Write a program, that reads a list and a sequence of instructions. Then show the final
list after following the instructions.
Input specification
You will be given an integer in the beginning (n) the number of instructions. Every instruction listed in a line
and starts with a letter P (Place new books to the desktop) or R (Remove books from the desktop):
After the letter P: you are given a number m: the number of new books. Then, you are given the IDs
of m new books that have just arrived.
After the letter R: you are given a number k, The officer have recorded k books from the top of the
lists (removed from the stack of books).
Explanation: There 4 instructions. The first instruction tells to place 3 books to desktop. Then one book is
removed (book with the ID 5). Then two new books are placed to the desktop. And then two books have been
recorded and removed by the officer. So, there are only two books waiting on the desktop: books 76 and 11.