|
|
@@ -14,8 +14,8 @@ RESULT_STR = [
|
|
|
]
|
|
|
|
|
|
|
|
|
-def compile_c(src_path):
|
|
|
- if os.system('gcc %s -o main' % src_path) != 0:
|
|
|
+def compile_c(src_path, out_path):
|
|
|
+ if os.system('gcc %s -o %s' % (src_path, out_path)) != 0:
|
|
|
return False
|
|
|
return True
|
|
|
|
|
|
@@ -69,13 +69,57 @@ def run(args, in_path, out_path, time_limit, memory_limit):
|
|
|
return rst
|
|
|
|
|
|
|
|
|
+def judge_by_cid(src_path, td_path, td_total, time_limit, memory_limit, language, cid):
|
|
|
+ main_dir = 'main-'+cid
|
|
|
+
|
|
|
+ args = []
|
|
|
+ src_file = ''
|
|
|
+ rst_list = []
|
|
|
+ if language == 'c':
|
|
|
+ if not compile_c(src_path, main_dir+'/main'):
|
|
|
+ return {'result_list': [{'result': RESULT_STR[7]}]}
|
|
|
+ args = ['./'+main_dir+'/main']
|
|
|
+ src_file = main_dir+'/main'
|
|
|
+ elif language == 'cpp':
|
|
|
+ if not compile_cpp(src_path):
|
|
|
+ return {'result_list': [{'result': RESULT_STR[7]}]}
|
|
|
+ args = ['./main']
|
|
|
+ src_file = 'main'
|
|
|
+ elif language == 'java':
|
|
|
+ if not compile_java(src_path):
|
|
|
+ return {'result_list': [{'result': RESULT_STR[7]}]}
|
|
|
+ args = ['java', 'Main']
|
|
|
+ src_file = 'Main.class'
|
|
|
+ time_limit *= 3
|
|
|
+ elif language == 'python':
|
|
|
+ if not compile_python(src_path):
|
|
|
+ return {'result_list': [{'result': RESULT_STR[7]}]}
|
|
|
+ args = ['python3', 'main.py']
|
|
|
+ src_file = 'main.pyc'
|
|
|
+ # 遍历每一个测试用例
|
|
|
+ for i in range(td_total):
|
|
|
+ in_path = os.path.join(td_path, '%d.in' % i)
|
|
|
+ out_path = os.path.join(td_path, '%d.out' % i)
|
|
|
+ if os.path.isfile(in_path) and os.path.isfile(out_path):
|
|
|
+ rst = run(args, in_path, out_path, time_limit, memory_limit)
|
|
|
+ rst['result'] = RESULT_STR[rst['result']]
|
|
|
+ rst_list.append(rst)
|
|
|
+ else:
|
|
|
+ os.remove(src_file)
|
|
|
+ rst_list.append({'result': RESULT_STR[8]})
|
|
|
+ return {'result_list': rst_list,
|
|
|
+ 'message': 'test data:%d incompleted' % i}
|
|
|
+ if os.path.exists(src_file):
|
|
|
+ os.remove(src_file)
|
|
|
+ return {'result_list': rst_list}
|
|
|
+
|
|
|
# 源代码文件,测试用例目录,测试用例个数,时间限制ms,内存限制KB,语言
|
|
|
def judge(src_path, td_path, td_total, time_limit, memory_limit, language):
|
|
|
args = []
|
|
|
src_file = ''
|
|
|
rst_list = []
|
|
|
if language == 'c':
|
|
|
- if not compile_c(src_path):
|
|
|
+ if not compile_c(src_path,''):
|
|
|
return {'result_list': [{'result': RESULT_STR[7]}]}
|
|
|
args = ['./main']
|
|
|
src_file = 'main'
|