Arrange Items for Solar Vehicle (Id-1501)

Bonus Practice Sheet Winter 2018 [17-Mar-2018 to 7-Apr-2018]

Program ID- 1501

There are ‘n’ bags in a corner of a city and they have to be moved to the centre of the city by a solar vehicle. The vehicle starts shunting from morning, the vehicle can carry more load in the mornings than in the evening when sunlight would be dimmer. Given the details of items in the bag, sort the bag in descending so that the vehicle can safely carry it to the centre of the city. Use vector and map in STL. Also use the sort algorithm defined in STL.

Hint: Use total weight of bag as key and object of bag as value, insert total weight of each bag into a vector. Use STL sort algorithm to sort it and print the details of bag in order

Input Format

Number of bags ‘n’

Name of bag1

Number of types of items in bag1, ‘t’

Weight of item1 in bag1

Number of item1 in bag1

Weight of item2 in bag1

Number of item2 in bag1

Weight of itemt in bag1

Number of itemt in bag1

….

….

Name of bagn

Number of types of items in bagn, ‘t’

Weight of item1 in bagn

Number of item1 in bagn

Weight of item2 in bagn

Number of item2 in bagn

Weight of itemt in bagn

Number of itemt in bagn

Output Format

Print name of bags in sorted order.

Sorting must be done in descending order based on the weight of the bag

Code

Please Comment Working if the code worked to you

If you have other working codes please comment the codes enclosing with <pre> and </pre> 🙂

Example: <pre> Your Code </pre>

C++ Code 

The Above Codes are for reference only. It doesn't mean everyone to directly copy/paste those codes.

 

Click Here to Leave a Comment Below 0 comments

Leave a Reply:

This site uses cookies and by using the site you are consenting to this.