Question

Cafeteria Queue Lunchtime is the most awaited time of the day for students in your school....

Cafeteria Queue Lunchtime is the most awaited time of the day for students in your school. Not only because there are no classes, but because the lunch is really good! At 12, all students run to the cafeteria and queue up for the meal.

Professor Yilma noticed that and decided to use it to encourage students to do better in his course. He convinced the cafeteria people to serve the students not in the order they arrived, but in order of their grades, highest to lowest. This way, students with higher grades get their lunch first.

Your task is simple: given the arrival time of the students in the cafeteria, and their respective grades in the math class, reorder the queue according to the math grades, and check how many students do not need to change place in this reordering.

Implement the function cafeteriaQueue(Q) that takes as input a list of the students in the queue, identified by their grades. For example, if the first students that arrived has grade 100, the second has grade 80, and the third student’s grade is 90, Q would be [100,80,90]. There will be no students with the same grade due to professor Yilma’s fine grained scoring system. This function returns the number of students that do not need to change places in line.

For example:

• cafeteriaQueue([100,80,90]) == 1

• cafeteriaQueue([100,120,30,50]) == 0

• cafeteriaQueue([100,90,30,25]) == 4

Homework Answers

Answer #1

Code for above program in python :- if u need code in any other language leave a comment and do give a thumbs up.

# function to calculate Number of students who do not need to change position
def cafeteriaQueue(queue):
    # creating a copy of the queue
    sortedqueue = queue.copy()
    # sorting the copied queue in descending order
    sortedqueue.sort(reverse=True)
    # initialising variable to keep sum of students who do not change position
    student = 0
    # iterating over both the lists
    for i in range(len(queue)):
        # checking if the position is same as earlier or not in the queue
        if queue[i] == sortedqueue[i]:
            # incrementing count
            student+=1
    return student

print(cafeteriaQueue([100,80,90]))
print(cafeteriaQueue([100,120,30,50]))
print(cafeteriaQueue([100,90,30,25]))

Screenshot for reference :-

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT
Active Questions
  • Need to determine the model equation for the conservation of energy it should have 5 terms...
    asked 8 minutes ago
  • Questions 5-15 are based on the following Ricardian model. Marginal Product of Labor                           Labor Force...
    asked 27 minutes ago
  • Construct a circuit for a 1 bit ALU in Logisim ,which can do AND,.OR,NOT, Addition, Subtraction.Use...
    asked 36 minutes ago
  • Vector A is directed along the positive y-axis and has magnitude √(3.0) units. Vector B is...
    asked 55 minutes ago
  • A random variable follows the continuous uniform distribution between 45 and 135. ​a) Calculate the probability...
    asked 1 hour ago
  • Be able to write Python programming of a factorial of an integer (given input parameters, output...
    asked 1 hour ago
  • A thumbs up will be given for correct answers that are fully worked out. The following...
    asked 1 hour ago
  • World Cultural Perspective Outline Competency 1 - Develop cultural self-awareness and other-culture awareness. Identify opportunities to...
    asked 1 hour ago
  • Assess how our socialization affects our views of gender roles
    asked 1 hour ago
  • v By steadily circulating Refrigerant-134a at low temperature through passages in the walls of the freezer...
    asked 1 hour ago
  • You are in charge of several Maternal and Child units at a large teaching hospital. The...
    asked 1 hour ago
  • This passage requires critcal response and analysis Denning (2013) states that Coase provided that firms exist...
    asked 1 hour ago