Question: How to solve that problem when I getting input from sys.stdin? for line in sys.stdin: l = line.split() ....... As I understand, I have to

How to solve that problem when I getting input from sys.stdin?

for line in sys.stdin:

l = line.split()

.......

As I understand, I have to check/iterate list which looks like:

Sample Input 1: 1 2 0 1 1 1 0 0

I try to do something like:

for line in sys.stdin: l = line.split() c = int(l[0][0]) n = int(l[0][1]) a = int(l[1][0]) b = int(l[1][1]) d = int(l[1][2]) a1 = int(l[2][0]) b1 = int(l[2][1]) d1 = int(l[2][2])

I tried as well but not working:

import sys

def train_journey(capability, depots, measures): num_passengers = 0 for i in range(depots): left, entered, staying = measures[i] num_passengers -= left if num_passengers < 0 or num_passengers + joined > capability: return 'impossible' num_passengers += entered if num_passengers < staying: return 'impossible' num_passengers -= staying if num_passengers == 0: return 'possible' else : return 'impossible' for line in sys.stdin: l = line.split() capability, depots = map(int, l) measures = [list(map(int, l)) for I in range(depots)] print(train_journey(capability, depots, measures))

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!