АЛЬТ+ тренировочный / std.sql.check

ru en cn

до начала осталось: 0:41
страница обновлена: 01.11.2024 16:18

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