4008 在线评判系统

img

img

img

img


能帮忙看看建设这样一个在线评判系统,使用Python语言,它的代码是多少吗?

  • 输入样例文件内容

    img

  • 代码运行效果截屏图片

    img

  • Python 代码
#!/sur/bin/nve python
# coding: utf-8


def read_one(f):
    ''' 从文件中读取一组评判数据 '''
    line = f.readline()
    
    if line.strip() == 'START':
        one = ''
        
        while 1:
            line = f.readline()
            
            if line.strip() == 'END':
                return one
            
            one += line
            

def is_blank(a, b):
    ''' 比对除空格回车外的字符串 '''
    a, b = [i for i in a if i not in ' \n'],  [i for i in b if i not in ' \n']
    
    if a == b:
        return True

    return False


def judge(filename):
    ''' 评判数据文件 '''

    with open(filename) as f:
        
        for i in range(int(f.readline())):
            target = read_one(f)
            user = read_one(f)
            is_blank(target, user)
            judge_tip = 'Accepted' if target == user else 'Presentation Error' if is_blank(target, user) else 'Wrong Answer'
            print(judge_tip)


if __name__ == '__main__':
    filename = '/sdcard/Documents/demo2.txt'
    judge(filename) # 调用函数评判输入文件。