Queue

17.6 - Priority queue basic 3


Your task is to create a program which receives a list of guest and prints out the order when they are entering based on how important that person is. The amount of V (Very) on their name determines how important they are, for example:

  • Douglas (no V, not important so priority = 0)
  • Victor (a V, very important so priority = 1)
  • Vivian (two Vs, very very important so priority = 2)

If there is a tie then the priority is determined alphabetically. For example, Aaron is more important than Boss.

To do this, you need to provide a custom functor (a struct/class which has the () operator overloaded) to compare the names. The skeleton code is provided for you.

Sample input

Victor
Bernie
Arthur
Vivian
Charles
Navy

Sample output

Vivian
Navy
Victor
Arthur
Bernie
Charles
#include <iostream> #include <string> #include <queue> #include <algorithm> struct compare_name { bool operator()(const std::string& lhs, const std::string& rhs) const { // Define your comparison method here. } }; int main() { std::priority_queue<std::string, std::vector<std::string>, compare_name> vip_queue; std::string name; while (std::cin >> name) { vip_queue.push(name); } while (!vip_queue.empty()) { std::cout << vip_queue.top() << std::endl;; vip_queue.pop(); } }