Issue
When the number of friends is entered and the status of a 10×10 movie theater is entered, if Chul-soo and his friends can watch the movie in the same line, write a program that outputs what line it is, or –1.
n=int(input())
lst=[list(map(int,input().split())) for _ in range(10)]
temp=-1
cnt=0
for i in range(0,10):
for j in range(0,10):
if lst[i][j]==0:
cnt+=1
else:
cnt=0
if cnt>=n:
temp=i+1
print(temp)
The code above shows 70 points
n=int(input())
lst=[list(map(int,input().split())) for _ in range(10)]
temp=-1
for i in range(0,10):
cnt=0
for j in range(0,10):
if lst[i][j]==0:
cnt+=1
else:
cnt=0
if cnt>=n:
temp=i+1
print(temp)
The code above will give you 100 points
The first code is to declare the cnt variable outside the for statement The second code is to declare the cnt variable in the for statement, but the score is different What's the difference? Please explain
python
For the second code, if cnt=0
is in the for statement, it will initialize to zero every time the for statement turns. This means that #10 cnt = 0
is executed.
The first code is cnt=0
outside the for statement, so cnt=0
will be executed only once, right?
It would be helpful if you could write down how the cnt changes and calculate it yourself.
887 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
599 GDB gets version error when attempting to debug with the Presense SDK (IDE)
572 Understanding How to Configure Google API Key
567 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
© 2024 OneMinuteCode. All rights reserved.