Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question#include#include#include#include#includeusing namespace std;struct Page { int id; string path; int counter; Page(int id, string path) { this->id = id; this->path = path; counter = 0;

Question#include#include#include#include#includeusing namespace std;struct Page { int id; string path; int counter; Page(int id, string path) { this->id = id; this->path = path; counter = 0; };};// This function can facilitate sortingbool operatorid = id; }; void add_visit(int page_id) { Page p(page_id, ""); vector::iterator iter = lower_bound(pages.begin(), pages.end(), p); if(iter->id == page_id) visits.push_back(iter->path); }; int size() const { return visits.size(); }; void print_visits() { sort(visits.begin(), visits.end()); vector::iterator iter; for(iter = visits.begin(); iter != visits.end(); iter++) { cout > type) { if(type == "USER") { int user_id; cin >> user_id; User u(user_id); add_user(u); } else if(type == "PAGE") { int page_id; string page_path; cin >> page_id; cin >> page_path; Page p(page_id, page_path); add_page(p); } else if(type == "VISIT") { int page_id; cin >> page_id; Page p(page_id, ""); vector::iterator iter = lower_bound(pages.begin(), pages.end(), p); if(iter->id == p.id) { iter->counter++; } add_visit(p.id); } } sort(pages.begin(), pages.end(), cmp_page_count); cout

image text in transcribed
Problem 1: Game of Elimination in C++ Consider a prize to be awarded to a winner among n > 0 contestants by a game of elimination. The n contestants first line up in a line, and are assigned the numbers 1 to n one by one. The host of the game then decides on an integer k > 1, and starting from contestant 1, the host counts k contestants down the line and eliminates the k-th contestants from the circle. He then continues to count for another k contestants. and eliminates the k-th contestants from the line. When he counts to the end of line, he will continue counting from the beginning of the line. This process repeats until there is only one contestant remains who will be the winner of the prize. For example, if n = 7 and k = 3. The initial line: 1234567, count to 3 and contestant 3 is eliminated Line now becomes: 124567. continue counting from 4 and contestant 6 is eliminated Line now becomes: 12457, continue counting from 7 and contestant 2 is eliminated Line now becomes 1457. continue counting from 4 and contestant 7 is eliminated Line now becomes 145, continue counting from 1 and contestant 5 is eliminated Line now becomes 14, continue counting from 1 and contestant 1 is eliminated Winner is contestant 4 Write a C++ proglam which impiements a circular linked list (see Module 8 Guidance Notes p.92) to determine which contestant will win the prize. Program input. Two input numbers n and k {n > 0 and k > 1). Program output. The winner of the game. Requirement: You will need to implement the circular linked list on your own, i.e., you may NOT use any STL containers or external linked list iibraries

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions