Школьный этап олимпиады 2017, 7-8 кл. / std.sql.check

ru en cn

с начала прошло: 2633 д. 00:24
страница обновлена: 27.12.2024 14:23

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)
Дальневосточный федеральный университет