0

codechef error nzec

T = int(input()) for i in range(T): N = int(input()) s = input() a=list(s) s=a j=0 i=0 for i in range(0,N-1): if a[i]==a[i+1]: if a[i]=='0': a[i+1]='1' j=j+1 else: if a[i]==s[i]: a[i]='0' j=j-1 print(j) this is my code ,its working on idle but on codechef its showing error, can anyone help me out.

23rd Mar 2019, 1:20 PM
yash Chitty
yash Chitty - avatar
7 ответов
+ 3
hi yash, I get an error when running the code: Traceback (most recent call last): File "help sololearn 2.py", line xy, in <module> if a[i]==a[i+1]: IndexError: list index out of range For me it's not very clear what you want to achieve with this code. Can you give us some more information?
23rd Mar 2019, 7:23 PM
Lothar
Lothar - avatar
0
What error is it showing? On a cursory look, I notice you have embedded for loops, both using the variable ‘i’ to iterate, which could cause an error. But the syntax looks correct at least.
23rd Mar 2019, 2:53 PM
Russ
Russ - avatar
0
Maybe change the variable of the top ‘for’ loop from ‘i’ to ‘k’?
23rd Mar 2019, 9:15 PM
Russ
Russ - avatar
0
the error is showing on the input line
2nd Apr 2019, 3:06 AM
yash Chitty
yash Chitty - avatar
0
the code is not able to take the input
2nd Apr 2019, 3:06 AM
yash Chitty
yash Chitty - avatar
0
There are N watchtowers built in a row. Each watchtower can only accommodate one person. Some of them are already occupied by members of the Night's Watch. Since the members of the Night's Watch do not get along, no two consecutive towers can be occupied at any moment. Arya heard that the wildlings are planning an attack. She is not satisfied by the current security, so she plans to place more members of the Night's Watch in the empty towers. What is the maximum number of people she can place in the towers such that no two consecutive towers are occupied afterwards? Note that Arya may not remove anyone from already occupied towers. Input The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains a single integer N. The next line contains a single string S with length N. For each valid i, the i-th character of this string is '1' if the i-th watchtower is initially occupied or '0' if it is empty.
2nd Apr 2019, 3:21 AM
yash Chitty
yash Chitty - avatar
0
Output For each test case, print a single line containing one integer — the maximum number of people Arya can place in the towers. Constraints 1≤T≤1,000 1≤N≤106 S contains only characters '0' and '1' initially, no two consecutive towers are occupied the sum of N over all test cases does not exceed 106 Subtasks Subtask #1 (20 points): initially, all towers are empty Subtask #2 (80 points): original constraints Example Input 2 6 010001 11 00101010000 Example Output 1 3 this is the senario given in codeshef so im a beginner so , not able to understand why my code is not running on codeshef it is running on my idle
2nd Apr 2019, 3:23 AM
yash Chitty
yash Chitty - avatar