Question
Complete this asignment using C++ code Rules Given a sequence of digits, modify the sequence by: Deleting all zeros, if any, and all the digits
Complete this asignment using C++ code
Rules
Given a sequence of digits, modify the sequence by:
Deleting all zeros, if any, and all the digits to their left
Changing a digit to a value less than that digit (by some set of rules).
Other Rules:
No negatives allowed.
In a real game the player who removes the last digit loses. We will just simulate.
Easy Version
For this program, given the sequence, remove all the zeros, if any, and all the digits to their left. Then find the largest remaining digit and if it is even subtract 2 from it or if it is odd subtract 1 from it. If two or more digits become tied as the largest digit, use the rightmost digit as the largest. Repeat the application of the rules to the sequence, then output how many moves were required to delete the sequence.
Two Sample Runs
Sample Input/Output
Hard Version
For this program, given the sequence, in one move remove all the zeros, if any, and all the digits to their left. Then find the digit that appears most frequently. Use the rightmost occurrence of that digit, and if it is even subtract 2 from it or if it is odd subtract 1 from it. If two or more digits tie as the most frequent digit, then use the largest such digit. If all the digits appear just once, use the largest digit. Repeat the application of the rules to the sequence, then output how many moves were required to delete the sequence.
Two Sample Runs
Sample Input/Output
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started