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:

  1. Deleting all zeros, if any, and all the digits to their left

  2. Changing a digit to a value less than that digit (by some set of rules).

Other Rules:

  1. No negatives allowed.

  2. 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

Moves

3 5 8 0 2 5 4

8 3 0 7 5 1

1

2 5 4

7 5 1

2

2 4 4

6 5 1

3

2 4 2

4 5 1

4

2 2 2

4 4 1

5

2 2 0

4 2 1

6

EMPTY

2 2 1

7

2 0 1

8

1

9

0

10

EMPTY

Sample Input/Output

Input

Ouput

7 3 5 8 0 2 5 4

6

6 8 3 0 7 5 1

10

5 5 0 6 0 4

4

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

Moves

2 0 4 3 2 3 1

5 2 0 3 3 1 1 2

1

4 3 2 3 1

3 3 1 1 2

2

4 3 2 2 1

3 2 1 1 2

3

4 3 2 0 1

3 2 1 1 0

4

1

EMPTY

5

0

6

EMPTY

Sample Input/Output

Input

Output

7 2 0 4 3 2 3 1

6

8 5 2 0 3 3 1 1 2

4

5 0 6 6 0 4

4


the input sequence can be an array

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!