Last active
December 27, 2017 07:51
-
-
Save snuke/d7723a99cd12ce90c191c6361b66a128 to your computer and use it in GitHub Desktop.
input checker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/python | |
import re, sys, os | |
re_num = '(0|-?[1-9]\d*)' | |
def check(fname, f): | |
lines = re.split(r'\r*\n',f.read()) | |
global li; li = 0 | |
def get(): | |
global li | |
in_s = lines[li]; li += 1 | |
return in_s | |
def getf(fmt): | |
in_s = get() | |
assert re.match('^%s$'%fmt, in_s), 'format : line {}'.format(li) | |
return in_s | |
def geti(): | |
return int(getf(re_num)) | |
def getis(n): | |
return list(map(int, getf('{0}( {0}){{{1}}}'.format(re_num,n-1)).split())) | |
def getil(*l): | |
if isinstance(l[0], int): | |
val = int(getf(re_num)) | |
assert l[0] <= val <= l[1], 'out of range : line {}'.format(li) | |
return val | |
vals = getis(len(l)) | |
for nx,nl in zip(vals,l): | |
assert nl[0] <= nx <= nl[1], 'out of range : line {}'.format(li) | |
return vals | |
def getils(l,r,n): | |
return getil(*[[l,r]]*n) | |
def eof(): | |
assert lines[li:] == [''], 'EOF' | |
MN = 10**5 | |
MA = 10**9 | |
n = getil(1,MN) | |
eof() | |
print('o') | |
if __name__ == '__main__': | |
for fname in sorted(os.listdir('../in/')): | |
if fname[0] == '.': continue | |
sys.stdout.write(fname + ': ') | |
with open('../in/' + fname) as f: | |
try: | |
check(fname, f) | |
except AssertionError as e: | |
print('invalid! ({})'.format(e)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/python | |
import re, sys, os | |
re_num = '(0|-?[1-9]\d*)' | |
def check(fname, f): | |
lines = re.split(r'\r*\n',f.read()) | |
global li; li = 0 | |
def get(): | |
global li | |
in_s = lines[li]; li += 1 | |
return in_s | |
def getf(fmt): | |
in_s = get() | |
assert re.match('^%s$'%fmt, in_s), 'format : line {}'.format(li) | |
return in_s | |
def geti(): | |
return int(getf(re_num)) | |
def getis(n): | |
return list(map(int, getf('{0}( {0}){{{1}}}'.format(re_num,n-1)).split())) | |
def getil(*l): | |
if isinstance(l[0], int): | |
val = int(getf(re_num)) | |
assert l[0] <= val <= l[1], 'out of range : line {}'.format(li) | |
return val | |
vals = getis(len(l)) | |
for nx,nl in zip(vals,l): | |
assert nl[0] <= nx <= nl[1], 'out of range : line {}'.format(li) | |
return vals | |
def getils(l,r,n): | |
return getil(*[[l,r]]*n) | |
def eof(): | |
assert lines[li:] == [''], 'EOF' | |
subtasks = 1 | |
MN = 10**5 | |
LN = [MN] | |
n = getil(1,MN) | |
eof() | |
def sub_check(id): | |
id -= 1 | |
if n > LN[id]: return 'length sub' | |
return '' | |
sid = fname[:2] | |
if sid.isdigit(): sid = int(sid) | |
else: sid = subtasks | |
res = sub_check(sid) | |
assert res == '', res | |
for i in range(1,subtasks+1): | |
sys.stdout.write('o' if sub_check(i) == '' else 'x') | |
print('') | |
if __name__ == '__main__': | |
for fname in sorted(os.listdir('../in/')): | |
if fname[0] == '.': continue | |
sys.stdout.write(fname + ': ') | |
with open('../in/' + fname) as f: | |
try: | |
check(fname, f) | |
except AssertionError as e: | |
print('invalid! ({})'.format(e)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment