10 AnswersNew Answer
This I think should work 🙂 https://code.sololearn.com/c7jJfPI2nuWb
You can salvage most of your code the following way: 1) Make dig1 one element larger and set dig1[count]=0. The reason is that your loop either includes one element too many or drops the last one. By adding one element more and setting it to 0, it is involved in the comparison, and will always be smaller than its predecessor. 2) Have the loop run while "i<count", to process all digits 3) Lose the "visited" flag and its "if". Instead, replace "continue" with "x++" to increase x to two digits having been processed. 4) fix the brackets after removing the "if(visited)" Now, it should work 🙂
I use bool statement because I noticed during interation if next letter is bigger than current then bigger is used twice. First at the substraction with current and second when it is itereted normally. So bool skip the second way.
Agnes, I have done as you said. But it is not possible to initialize variable-sized object. Nothing happens, last letter is still not in account. Can you make corrections?
But it write down the right size of array when I print count. I consider the size when I am copying the numbers into array in switch statement. Seems strange.
I 'm going to test it if it is really possible. Thanks.
It will be, I'm sure 🙂🍀 Incidentally, the "visited" flag is not necessary, because there are only two logical paths. And "count[x] < count[x+1]" is the same as "visited". So, no need for the boolean flag. As a matter of fact, it is one of the problems you have now, because you forgot to reset the flag to "false". And the "continue" statement has you skip the output - so, that needs to go, too.
Yes, but you can skip already when checking the digits for their numerical value 🙂
Just noticed, you did not specify the correct size for count. I have added that now.
The array does not adjust its size later. It is sized the moment it is created, and at that time, count is zero.