Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please coding this question with C++ and comment the codes. Use simple code if possible, thank you. 4 (25 points) No answer yet The user
Please coding this question with C++ and comment the codes. Use simple code if possible, thank you.
4 (25 points) No answer yet The user input consists of a sequence of numbers from the set {1,2,3} followed by the number -1 that signifies the end of the input. Make the program that repeatedly performs the following operation on the entire sequence until the sequence gets transformed into one that has all terms equal: In each step, starting from the left we identify the first two terms of the sequence that are different from each other. Then we remove these two terms and replace them by one single term that is equal to neither of the two original terms. For example (12) is replaced by 3; (21) is replaced by 3; (32) is replaced by 1. Example: Input: 1112 331 2 2 13 3-1 Output: 3 3 3 3 2 Explanation: The terms of the sequence are 2o = 1, 11 = 1, 12 = 1, 23 = 2, 14 = 3, 25 = 3, 26 = 1, 27 = 2, 2g = 2, 19 = 1, 210 = 3 ,211 = 3. In the first step, we identify the terms 22 and 23 that are different from each other and replace them by a single term 2. We obtain the sequence 1133312 213 3. This can be summarized in the following way 11 12 3 3 12 2133 113 3312 2133 12 3312 2133 33 2 2133 3 2,2 2133 32 22133 22 22 33 2 22 33 3 32 2 1 2 32 33 333Step 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