last lab
This commit is contained in:
24
labPython/lab4/MinMax27.py
Executable file
24
labPython/lab4/MinMax27.py
Executable file
@@ -0,0 +1,24 @@
|
||||
import random
|
||||
|
||||
nBit = int(input("Введите количество элементов N: "))
|
||||
bitArray = [random.randint(0, 1) for _ in range(nBit)]
|
||||
print(bitArray)
|
||||
countLen = 0
|
||||
countIndex = 0
|
||||
bitMax = 0
|
||||
bitMaxIndex = 0
|
||||
for i in range(len(bitArray)):
|
||||
if i < len(bitArray)-1:
|
||||
if bitArray[i] == bitArray[(i+1)]:
|
||||
countLen +=1
|
||||
if countLen > bitMax:
|
||||
bitMax = countLen
|
||||
bitMaxIndex = (i+2) - bitMax
|
||||
# countLen = 0
|
||||
|
||||
else:
|
||||
countLen = 0
|
||||
bitMax += 1
|
||||
|
||||
|
||||
print(bitMax, bitMaxIndex)
|
||||
Reference in New Issue
Block a user