Posted on someone asked, from the terminal read into an integer n, random one input a 0 or 1
Determine the maximum number of consecutive 0 or 1. Such as:
Input
0
0
0
1
1
1
1
0
1
0
1 in continuous input, there are 4 times
#coding: Utf-8
"" Python Beijing Weekend training Course
Https://github.com/pythonpeixun/article/blob/master/beijing_weekend.md
Python Shanghai Weekend Course
Https://github.com/pythonpeixun/article/blob/master/shanghai_weekend.md
Inquiry: Written by qq:1465376564 Huanggo
The idea of doing this exercise is to add 0 or 1 to a list with an n cycle first,
Finally, a dictionary is used to count the maximum number of consecutive 0 or 1 occurrences.
"""
Input_lst = []
Dict_num = {}
n = Int (raw_input ("Please input n:\n"). Strip ())
For I in Xrange (n):
Number = Int (raw_input ("Please input number:\n"). Strip ())
Input_lst.append (number)
length = Len (input_lst)
For I, item in enumerate (INPUT_LST):
If 0 < i < length:
If input_lst[i] = = Input_lst[i-1]:
If item in Dict_num:
Dict_num[item] + = 1
Else
Dict_num[item] = 1
Print Input_lst
Print Max (Dict_num.values ())
Python determines the maximum number of consecutive 0 or 1