2

How to Serve a Coffee? (Id-1537)

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

Program ID- 1537

 

Jegan organizes a family function and invite some of his friends. Many of his friends come prior to the function. Jegan has arranged for their accommodation in a hotel. The rooms are booked as the guest arrive, so the room numbers are not continous and not in any order. Jegan has the room number of the friend who had arrived first. And he has requested his friends to have a room number of the person who arrives next to him. That is the friend who arrived third will have room number of the friend who arrived fourth. The last guest will not have any room number. Given the details of each guest such as name, his room number and room number of the guest who arrived next, and room number of that Jegan has, design an algorithm and write a C++ code to print the names and room numbers to serve a coffee. For example, if the details in the following table is given

 

Room Number of GuestName of GuestRoom number the guest who arrived next
125John210
157Kannan125
210Kumar-1
315Anand157

 

If Jegan has room number as 315, room number of the friend who arrived first, then the output should be

Anand 315

Kannan 157

John 125

Kumar 210

Hint: Map in STL can be used for representing the input, room number of the guest may be the key and other two details may be stored as value by representing them as a user defined data type.

Input Format

Number of friends

Room number of guest1

Name of guest1

Room number the guest who arrived next to guest1

Room number of guest2

Name of guest2

Room number the guest who arrived next to guest2

….

Room number of guestn

Name of guestn

-1 ( Last guest doesn’t posses any room number)

Room number that Jegan has

Output Format

Name of guest1 and his Room number separated by tab

Name of guest2 and his Room number separated by tab

Name of guestn and his Room number separated by tab

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.

 

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