Kodewick
Start learning →
Starter←→0 / 60

Hotel rooms

#028StarterMaps3 min

The hotel front desk looks up room numbers by guest name. Write room_of(rooms, guest): if the guest is in rooms, return their room number; if not, return 0.

Examples
room_of({{"Amy", 101}, {"Bao", 205}}, "Bao")→205
room_of({{"Amy", 101}}, "Zed")→0
The functionint room_of(const map<string, int> &rooms, const string &guest)
main.cpp
#include <map>
#include <string>
using namespace std;

int room_of(const map<string, int> &rooms, const string &guest) {
    // your code here: if the guest is there, return their room number
    return 0;
}
Ctrl + Enter runs too
Result

Run tries the examples. When they look right, Submit.