mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2024-09-21 08:23:20 +00:00
判题中输出结果的比较去除最后的空行和空格
This commit is contained in:
parent
1dc0e8b742
commit
0c0d4225ca
@ -1,4 +1,5 @@
|
||||
# coding=utf-8
|
||||
import os
|
||||
import json
|
||||
import commands
|
||||
import hashlib
|
||||
@ -94,7 +95,8 @@ class JudgeClient(object):
|
||||
return error, parse_lrun_output(output)
|
||||
|
||||
def _compare_output(self, test_case_id):
|
||||
test_case_md5 = self._test_case_info["test_cases"][str(test_case_id)]["output_md5"]
|
||||
test_case_config = self._test_case_info["test_cases"][str(test_case_id)]
|
||||
test_case_md5 = test_case_config["output_md5"]
|
||||
output_path = judger_workspace + str(test_case_id) + ".out"
|
||||
|
||||
try:
|
||||
@ -104,6 +106,7 @@ class JudgeClient(object):
|
||||
return False
|
||||
|
||||
# 计算输出文件的md5 和之前测试用例文件的md5进行比较
|
||||
# 现在比较的是完整的文件
|
||||
md5 = hashlib.md5()
|
||||
while True:
|
||||
data = f.read(2 ** 8)
|
||||
@ -111,9 +114,18 @@ class JudgeClient(object):
|
||||
break
|
||||
md5.update(data)
|
||||
|
||||
# 对比文件是否一致
|
||||
# todo 去除最后的空行
|
||||
return md5.hexdigest() == test_case_md5
|
||||
if md5.hexdigest() == test_case_md5:
|
||||
return True
|
||||
else:
|
||||
# 这时候需要去除用户输出最后的空格和换行 再去比较md5
|
||||
# 兼容之前没有striped_output_md5的测试用例
|
||||
if "striped_output_md5" not in test_case_config:
|
||||
return False
|
||||
f.seek(0)
|
||||
striped_md5 = hashlib.md5()
|
||||
# 比较和返回去除空格后的md5比较结果
|
||||
striped_md5.update(f.read().rstrip())
|
||||
return striped_md5.hexdigest() == test_case_config["striped_output_md5"]
|
||||
|
||||
def _judge_one(self, test_case_id):
|
||||
# 运行lrun程序 接收返回值
|
||||
|
@ -198,16 +198,24 @@ class TestCaseUploadAPIView(APIView):
|
||||
# 计算输出文件的md5
|
||||
for i in range(len(l) / 2):
|
||||
md5 = hashlib.md5()
|
||||
striped_md5 = hashlib.md5()
|
||||
f = open(test_case_dir + str(i + 1) + ".out", "r")
|
||||
# 完整文件的md5
|
||||
while True:
|
||||
data = f.read(2 ** 8)
|
||||
data = f.read()
|
||||
if not data:
|
||||
break
|
||||
md5.update(data)
|
||||
|
||||
# 删除标准输出最后的空格和换行
|
||||
# 这时只能一次全部读入了,分块读的话,没办法确定文件结尾
|
||||
f.seek(0)
|
||||
striped_md5.update(f.read().rstrip())
|
||||
|
||||
file_info["test_cases"][str(i + 1)] = {"input_name": str(i + 1) + ".in",
|
||||
"output_name": str(i + 1) + ".out",
|
||||
"output_md5": md5.hexdigest(),
|
||||
"striped_output_md5": striped_md5.hexdigest(),
|
||||
"output_size": os.path.getsize(test_case_dir + str(i + 1) + ".out")}
|
||||
# 写入配置文件
|
||||
open(test_case_dir + "info", "w").write(json.dumps(file_info))
|
||||
@ -239,8 +247,6 @@ def problem_list_page(request, page=1):
|
||||
else:
|
||||
difficulty_order = "difficulty"
|
||||
|
||||
|
||||
|
||||
# 按照标签筛选
|
||||
tag_text = request.GET.get("tag", None)
|
||||
if tag_text:
|
||||
|
Loading…
Reference in New Issue
Block a user