Week 12

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Week 12 – Stacks and Queue (or Doubly)

Exercise 1: FILE + QUEUE + LINKED LIST (at least 5 functions)


Create a C program for a Coffee Shop that handles customer orders. Whenever a customer places an order, a
new order will be added to a queue. Once the order is served to the customer, it will be removed from the queue.
Each order consists of an ID and total price. The program must be able to show the pending orders and store the
number of pending orders. It's important to store the pending orders persistently, even if the program is closed or
restarted.
Note: Press 1 to add order, -1 to server order, 2 to show pending orders, 0 to stop.

Exercise 2: FILE + STACK + LINKED LIST


Develop a C program for a Transportation Company to be used in each vehicle. This program will handle the
package information stored in the vehicle. Whenever a package is delivered, it will be removed from the stack
of packages. On the other hand, when a package is taken from the warehouse, it will be added to the stack. Each
package consists of a Code, wight and Address (just one string). The packages which are not delivered must be
stored in a file and accessible for the next transportation.
Note: Press 1 to add package, -1 to deliver, 2 to show not delivered, 0 to stop.

50755 - Top N Donors - 1 (USE INSERT SORTED): http://acm.epoka.edu.al:8888/en/problem-pid-c643

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.

Sample Input I Sample Input II


6 4 10 5
Erma Gomez 85 Archie Cortez 366.8
Christopher Hampton 352 Carla Caldwell 1664.5
Geraldine Craig 335 Don Townsend 4435
Barbara Bennett 8 Drew Stewart 3520
Carmen Horton 375.5 Emanuel Hines 3262
Margie Reid 405 Lloyd Parks 5965
Marcia Phillips 2327
Oliver Burgess 748
Robin Collins 774
Rosemary Rice 4240.7
Sample Output I Sample Output II
Margie Reid 405 Lloyd Parks 5965
Carmen Horton 375.5 Don Townsend 4435
Christopher Hampton 352 Rosemary Rice 4240.7
Geraldine Craig 335 Drew Stewart 3520
Emanuel Hines 3262
50364 - Student averages (SORT AFTER READING ALL
DATA): http://acm.epoka.edu.al:8888/en/problem-pid-c4bc

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:

 Name: At most 15 chars string containing only English letters.


 Surname: At most 15 chars string containing only English letters.
 4 Marks: 4 integer numbers between 0 and 100

Output specification
Show top m students' names surnames and averages (with 2 decimal places after the floating point).

Sample Input I Sample Output I


6 3 Erma Gomez 78.75
Erma Gomez 89 81 76 69 Barbara Bennett 75.5
Geraldine Craig 40 69 73 49 Carmen Horton 74.5
Margie Reid 44 55 63 63
Barbara Bennett 96 54 75 77
Christopher Hampton 48 72 59 87
Carmen Horton 56 68 90 84

50985 - Books Waiting (LIFO / Stack of Books): http://acm.epoka.edu.al:8888/en/problem-pid-c729

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).

where 0 ≤ n ≤ 5,000 and 0 ≤ m ≤ 100


Output specification:
Show the IDs of the books still waiting on the desktop. Show a zero "0" if there is no book waiting.

Sample Input I Sample Input 2


4 7
P 3 11 76 5 P 5 68 3 10 100 99
R 1 P 6 28 4 33 47 80 15
P 2 13 58 R 6
R 2 R 2
P 3 26 9 61
R 4
P 3 59 52 53

Sample Output I Sample Output 2


76 11 53 52 59 3 68

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.

You might also like