ACM 2003 Test tour / std.sql.check

ru en cn

с начала прошло: 7696 д. 04:09
страница обновлена: 25.11.2024 22:29

std.sql.check: check.py

import sys
from json import loads

ERR_OK = 0
ERR_WA = 1
ERR_PE = 2
ERR_UH = 3

with open(sys.argv[3], 'r') as fans, open(sys.argv[2], 'r') as fout:
    eans = int(fans.readline())
    eout = int(fout.readline())

    if eout != ERR_OK: print(fout.read()); exit(eout)

    lans = loads(fans.read())
    lout = loads(fout.read())

    if lout != lans:

        if lout and len(lout[0]) != len(lans[0]):
            print('Incorrect number of columns!')
            exit(ERR_WA)

        if len(lout) > len(lans):
            print('Too many rows in output!')
            exit(ERR_WA)

        if len(lout) < len(lans):
            print('Too few rows in output!')
            exit(ERR_WA)

        #Data checking:
        hans = set(tuple(it) for it in lans)
        hout = set(tuple(it) for it in lout)
        if hout == hans:
            print('List is not sorted!')
        else:
            print('Row mismatch!')
            for rans, rout in zip(sorted(hans - hout), sorted(hout - hans)):
                print('ans:', rans)
                print('out:', rout)
                print()
        exit(ERR_WA)

exit(ERR_OK)
Дальневосточный федеральный университет