Your family frequently spends the day at magic kingdom. The last hour is often w
ID: 663127 • Letter: Y
Question
Your family frequently spends the day at magic kingdom. The last hour is often wasted just trying to figure out which rides should be visited to make the best of the remaining time. In the end, you often just decide choose a random ride even if it is not really one that you like. You have plans to visit Disney this weekend, since your family will have visitors from out of town. You do not want the last hour to spoil their memories of the day, so you have decided to create an app which can select the rides to visit to make the most efficient use of the last hour. Your app will prompt a user for the wait times for each of 5 rides. The wait times will be given as a whole number of minutes. Assuming that wait times will not change within the hour and every ride runs for exactly 2 minutes, find the 3 rides that will make the best use of your time. You may not go over the 60 minutes but you should make the most possible use of the time. This means that you should have the minimum amount of time over. You may also assume that the time taken to walk from a ride to another is 3 minutes.
When run, your program should output the rides that should be selected for the last 60 minutes
Language is C
Explanation / Answer
// file BestRides.c
#include<stdio.h>
//////////////////////////// Function to calculate Best Rides/////////////////////////
int bestRides(int *ar,int *ride)
{
int temp;
// Performing sorting on wait time
for(int i=0;i<5;i++)
{
for(int j=i+1;j<5;j++)
{
if(ar[i]>ar[j])
{
temp=ar[i];
ar[i]=ar[j];
ar[j]=temp;
temp=ride[i];
ride[i]=ride[j];
ride[j]=temp;
}
}
}
int TotalTime=0,count=0;
// finding Best Rides which Can be Completed with in 60 Minutes.
for(int i=0;i<5;i++)
{
TotalTime +=ar[i]; // Wait time
TotalTime +=2; //time of Ride=2 minutes
if(TotalTime<60) // Total Time should be less than 60 minutes
{
count++;
TotalTime +=3; //Time to walk=3 minutes
}
else
{
break;
}
}
if(count>0)
{
printf("only %d rides can be taken. ",count);
printf("The rides are :");
for(int i=0;i<count;i++)
{
printf("%d ",ride[i]);
}
}
else
printf("NO ride can be taken.");
return 0;
}
int main()
{
int wait[5],ride[5];
printf("Enter the Wait time for the % rides ");
for(int i=0;i<5;i++)
{
scanf("%d",&wait[i]);
ride[i]=i+1;
}
bestRides(wait,ride); // Function call
return 0;
}
Output:
1.
Enter the Wait time for the rides
5 60 10 30 50
only 3 rides can be taken.
The rides are :1 3 4
Output 2.
Enter the Wait time for the rides
80 5 20 60 20
only 3 rides can be taken.
The rides are :2 3 5
Output 3:
Enter the Wait time for the rides
20 40 50 5 70
only 2 rides can be taken.
The rides are :1 4
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.