1. For a group of continuous data, after the order is disrupted, a number is randomly taken out (after a number is taken out, all the digits after the position are moved forward by one digit ), find the number in the simplest way.
2. for expansion of 1, when multiple data items are taken out, the easiest way is to find the number.
I began to abstract the scenario 1 into a general model, jumped into the thinking trap, and figured it out. I was dizzy ....
You can also try to write it first. The following code is not the best (pure test code) and serves only as a reference.
The code for 1 is as follows:
? FindDeletedOneElement (totalLength, firstValue, (totalLength <= [] array = length = [] arrayCopy = randomIndex = random. next (deletedValue = arrayResultLength = (index =; index <length; index ++ (index <-= + = List <> () {deletedValue },FindDeletedOneElement
The code for 2 is as follows:
IList <> FindDeletedElements (totalLength, firstValue, exchangeCount, (totalLength <= [] array = length = [] arrayCopy =? [] ArrayFilled =? (Index =; index <array. length; index ++ currentValue = position = currentValue-= <> deletedValues = List <> (index =; index <length; index ++ (arrayFilled [index] = +FindDeletedElements
All code is as follows:
Main (firstValue =-totalLength =, IList <> FindDeletedElements (totalLength, firstValue, exchangeCount, (totalLength <= [] array = length = [] arrayCopy =? [] ArrayFilled =? (Index =; index <array. length; index ++ currentValue = position = currentValue-= <> deletedValues = List <> (index =; index <length; index ++ (arrayFilled [index] ==+ DeleteData ([] array, (array = | array. length = | count <| count> = (index =; index <count; index ++ randomIndex = random. next (? FindDeletedOneElement (totalLength, firstValue, (totalLength <= [] array = length = [] arrayCopy = randomIndex = random. next (deletedValue = arrayResultLength = (index =; index <length; index ++ (index <-= + = List <> () {deletedValue}, Output (IList <> deletedValues, (deletedValues === (value + Exchange ([] array, (array = | array. length <= | count <= (index =; index <count; index ++ startIndex = randomIndex. next (endIndex = randomIndex. next (startIndex = tempValue = DeleteRandomIndexData ([] array, (array = length = (randomIndex <| randomIndex> = (index = randomIndex; index <length -; index ++ = array [index + = array. take (length-[] CreateArray (count, (count <= [[] array = (index =; index <count; index ++ = ++Program
Everyone has good ideas to write and learn...