ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1196. History Exam

How to do faster I/O using Python, similar to scanf in C++?
Posted by DR. Zhihua Lai 2 Apr 2013 20:40
#!/usr/bin/env python

from sys import stdin

n = int(stdin.readline())
p = [0] * n
for i in xrange(n):
    p[i] = int(stdin.readline())

def chk(s, p, n):
    left = 0
    right = n - 1
    while left <= right:
        mid = (left + right) / 2
        if s > p[mid]:
            left = mid + 1
        elif s < p[mid]:
            right = mid - 1
        else:
            return True
    return False
c = 0
m = int(stdin.readline())
for i in xrange(m):
    s = int(stdin.readline())
    if chk(s, p, n):
        c += 1

print c


The above code is TL8.