for code snippets

Wednesday, November 16, 2016

Competitive Programming In Python 3.x

Though I prefer C++ for competitive programming and problem solving, but sometimes python can be of great help.Specially when big data needs to be handled. So I felt an urge to note down basic input-output or other things in python.

Here I will use python 3.x.

Input-Output:

#Take input while End Of File:

while True:
        try:
             n=input()
        except EOFError:
             break;


#Take space separated int inputs:


while True:
        try:
             inp=input()
        except EOFError:
             break;
        n,m=inp.split()
        n=int(n)
        m=int(m)
#Take input while a certain conditions are met.
while True:
        inp=input()
        n,m=inp.split()

        n=int(n)
        m=int(m)
        if n==0 and m==0:
                break


Array related:

Two dimensional Array initialized with zero:
array=[[0 for x in range(102)] for y in range(102)]



No comments:

Post a Comment