Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Larry Ellison Database Genius Of Oracle

Authors: Craig Peters

1st Edition

0766019748, 978-0766019744

More Books

Students also viewed these Databases questions

Question

9. Describe the characteristics of power.

Answered: 1 week ago

Question

10. Describe the relationship between communication and power.

Answered: 1 week ago