-
Notifications
You must be signed in to change notification settings - Fork 1
/
problem2.py
61 lines (50 loc) · 1.44 KB
/
problem2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
'''
# Sample code to perform I/O:
name = raw_input() # Reading input from STDIN
print 'Hi, %s.' % name # Writing output to STDOUT
# Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail
'''
# Write your code here
import math
def add1(digits,index):
newdigits = list(digits)
if index <= len(newdigits)-1:
newdigits[index-1] = str(1)
return ''.join(newdigits)
def countmaxsub1s(digits):
newdigits = list(digits)
maxcount=0
count=0
previndex=0
index=0
# print(newdigits)
for index in range(len(newdigits)):
if int(newdigits[index-1]) == 1:
count+=1
if(previndex) ==0 or index-previndex==1:
previndex = index-1
if count >maxcount:
maxcount=count
index+=1
return maxcount
def main():
line = raw_input()
[n,k] = line.split(' ')
if(math.isnan(int(n)) or math.isnan(int(k))):
return
digits = raw_input()
if not(len(digits)==int(n)):
return
inputindex = 0
while inputindex < int(k):
line = raw_input()
items = line.split(' ')
if len(items) == 1 and int(items[0]) == 1:
print(countmaxsub1s(digits))
if len(items) == 2 and int(items[0]) == 2:
digits=add1(digits,int(items[1]))
print(digits)
inputindex+=1
return
if __name__ == "__main__":
main()