Part 1: Array Game: Develop a program in C++ that finds the winner of a game...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Part 1: Array Game: Develop a program in C++ that finds the winner of a game that is played amongst different elements of an array of distinct integers as per the following rule: A game will be played between the first two elements of the array (for example - arr[0] and arr[1], if the name of the array is arr[]). In each round of the game, compare arr[0] with arr[1], the larger integer wins and remains at position 0, and the smaller integer moves to the end of the array. The game ends when an integer wins 'k' consecutive rounds. It is guaranteed that there will be a winner of this game. Your program should ask the user to input an array of distinct integers, its size, and an integer 'k'. It should return the integer which will win the game. For instance, if the user enters an array consisting of the elements - 2,1,3,5,4,6,7 and the value of k as 2, then the following is the way the game runs: Round | 1 arr | [2,1,3,5,4,6,7] | 2 | winner | win_count 1 2 | [2,3,5,4,6,7,1] | 3 3 | [3,5,4,6,7,1,2] | 5 1 4 |[5,4,6,7,1,2,3] | 5 | 2 So, we can see that 4 rounds will be played and 5 is the winner because it wins 2 consecutive games. Sample Input/Output Example 1: Input: Enter the size of the array: 7 Enter the array elements: 2 1 3 5 4 6 7 Enter the value of k: 2 Output: The winner is 5 Part 1: Array Game: Develop a program in C++ that finds the winner of a game that is played amongst different elements of an array of distinct integers as per the following rule: A game will be played between the first two elements of the array (for example - arr[0] and arr[1], if the name of the array is arr[]). In each round of the game, compare arr[0] with arr[1], the larger integer wins and remains at position 0, and the smaller integer moves to the end of the array. The game ends when an integer wins 'k' consecutive rounds. It is guaranteed that there will be a winner of this game. Your program should ask the user to input an array of distinct integers, its size, and an integer 'k'. It should return the integer which will win the game. For instance, if the user enters an array consisting of the elements - 2,1,3,5,4,6,7 and the value of k as 2, then the following is the way the game runs: Round | 1 arr | [2,1,3,5,4,6,7] | 2 | winner | win_count 1 2 | [2,3,5,4,6,7,1] | 3 3 | [3,5,4,6,7,1,2] | 5 1 4 |[5,4,6,7,1,2,3] | 5 | 2 So, we can see that 4 rounds will be played and 5 is the winner because it wins 2 consecutive games. Sample Input/Output Example 1: Input: Enter the size of the array: 7 Enter the array elements: 2 1 3 5 4 6 7 Enter the value of k: 2 Output: The winner is 5
Expert Answer:
Related Book For
Microeconomics An Intuitive Approach with Calculus
ISBN: 978-0538453257
1st edition
Authors: Thomas Nechyba
Posted Date:
Students also viewed these programming questions
-
Using an Esp32, write a program in C that scrapes off a website and prints the entire website to the serial monitor. Do not download the website, you should be able to read off the website by...
-
Your program should ask the user for the name of an XML file containing a list of URLs for RSS v2.0 feeds (see below for the format of this file) and for the name of an output file in which to...
-
Write a program in C about Personal Diary Management System. The code must contain a function, file, structure. Please give full code in the screenshot on IDE with the output screenshot.
-
What is the expected spot rate at the end of the year assuming PPP? initial spot rate 87.60 Expected US inflation 2.20% Expected Japanese yen inflation 0.00%
-
North Pole Cruise Lines issued preferred stock many years ago. It carries a fixed dividend of $6 per share. With the passage of time, yields have soared from the original 6 percent to 14 percent...
-
A plane wall of thickness 2L has internal heat sources whose strength varies according toqG = q0 cos (ax)where q0 is the heat generated per unit volume at the center of the wall (x = 0) and a is a...
-
Do the following activities to complete your marketing plan: 1. Draw a simple organizational chart for your organization. 2. Develop a Gantt chart (see Chapter 2) to schedule the key activities...
-
The Colonial House Furniture Company manufactures two-drawer oak file cabinets that are sold unassembled through catalogues. The company initiates production of 150 cabinet packages each week. The...
-
When discussing possible purchase of a fixed immediate annuity, not discussing the full range of available annuitization options and the implications of choosing one over another, particularly with...
-
Congratulations! You've just been hired by a company as their new Quality Manager. They are a large manufacturer of parts for the aerospace industry. The boss sits you down on the first day and...
-
A trader wants to take a short position in an on-the-run 20-year US Treasury bond with a $4,000,000 face value. The trader plans to enter into a 20-day reverse repo transaction at a quoted repo rate...
-
What are the 3 key differences between NoSQL and SQL? List 3 examples of NoSQL DBMS. In what situation/scenario would it be better to use a NoSQL database over an SQL database?
-
Select the letter of the item that best matches each definition. a. company name b. Test Drive c. Activities d. QuickBooks Online e. QuickBooks Desktop f. Reports g. New Company Setup h. QuickBooks...
-
5. At the end of the year, Kiehnau Kicks had $11,400 in inventory, $23,470 in fixed assets, $13,240 in accounts receivable, $9,760 in accounts payable, $5,350 in long-term debt, and $4,820 in cash....
-
ALICE Essential Index After reviewing the website and reading the latest report, answer the following prompts: Describe how the ALICE Essential Index is different than the CPI. Explain which...
-
We know that taxation and monopolies generate deadweight loss. If the product of a monopolist firm is taxed show the deadweight loss on a graph and discuss what would happen to consumer and producer...
-
Organization XYZ has as of late obtained another auxiliary. As the bookkeeper for Organization XYZ, you are entrusted with merging the fiscal summaries of the auxiliary with those of the parent...
-
Use translations to graph f. f(x) = x-/2 +1
-
The tax analyzed in exercise 3.15 is a proportional wage tax. The U.S. federal income tax, however, is progressive. This means that the average tax rate one pays increases the more wage income is...
-
There are many equity or fairness based arguments for government engagement in anti-poverty programs and for general government redistribution programs. But is there an efficiency case to be made...
-
Trade, Migration and the Price of a Haircut: In the text, we discussed the similarities between outsourcing and immigration and with it the similarity between trading goods and moving workers. The...
-
Consider the dynamic system, a mass, spring and damper structure, shown in Figure 2.2. (a) Draw a free-body diagram for the dynamic system (b) Derive the Input-Output model of the dynamic system k...
-
Two connected cars with an applied input force \(u(t)\) and negligible rolling friction can be represented by a translational mechanical system as shown below. (a) Draw the free-body diagrams of this...
-
Consider an RLC circuit consisting of a resistor \((R)\), an inductor \((L)\), and a capacitor \((C)\), connected in series, as depicted in Figure 2.4. Derive the Input-Output model of the network....
Study smarter with the SolutionInn App