How to read input filr from SPOJ in python...for example spoj.pl/problems/HOTELS/111 i have to read input file but i don't know how to read input from spoj file???
created
last reply
- 8
replies
- 2.9k
views
- 3
users
- 4
links
How to read input filr from SPOJ in python...for example spoj.pl/problems/HOTELS/111 i have to read input file but i don't know how to read input from spoj file???
All you need to know about file reading in Python you find here:
http://docs.python.org/release/2.6.6/library/stdtypes.html#file-objects215
But to solve SPOJ problems there is no need of reading a file. You get all the input via stdin.
You already solved problem JULKA - just read the input of HOTELS the same way.
i tried to solve spoj.pl/problems/HOTELS/26 in python i have already submitted it in C++..but it is not code in python shows error...in this probelm we need to read test case from file of problem...but i have taken n(number of input ) from user..my qestion is how to read teat case of file given in problem...
n=int(input())
v=int(input())
s=0;
l=[]
while(s<=n-1):
integerinput=int(input())
l.append(integerinput)
s+=1
maxhere=maxsofar=i=j=k=0
while(i<=n-1):
if(maxhere+l[i] maxhere=max(0,maxhere+l[i])
i+=1
elif(maxhere+l[i]==v):
maxsofar=maxhere+l[i]
break
else:
maxsofar=max(maxhere,maxsofar)
maxhere=maxhere-l[k]
k+=1
print (maxsofar)
@numerix
ok then help me m getting NZEC in problem while i have submitted same in C++ my python code for problem is
n=int(input())
v=int(input())
s=0;
l=[]
while(s<=n-1):
integerinput=int(input())
l.append(integerinput)
s+=1
maxhere=maxsofar=i=j=k=0
while(i<=n-1):
if(maxhere+l[i] maxhere=max(0,maxhere+l[i])
i+=1
elif(maxhere+l[i]==v):
maxsofar=maxhere+l[i]
break
else:
maxsofar=max(maxhere,maxsofar)
maxhere=maxhere-l[k]
k+=1
print (maxsofar)
please check out..and match it output as given problem it will work in all case please help me..and tell me how to submit it ..looking forward for your helping hand..i am newbie in python and justed shifted from C++ to python