将lemon/Atcoder下的数据转成UOJ支持的格式

背景

很多时候OI考试都是使用lemon进行评测的,但是赛后把题目放到OJ上会更方便补题一些。由于很多OI题数据点很多,一个一个复制改名会很累,所以写一些py脚本来改格式就会方便很多。

UOJ下的数据格式具体可以看社区版的wiki

代码

传统题

import os, shutil

cnt = {}
tot = 0
pre = 'data'
firstsuf = 'unknown'
in_suf, out_suf = 'in', 'out'
time_limit = 1
memory_limit = 128
output_limit = 64
n_ex_tests = 1
n_sample_tests = 1

for root, dirs, files in os.walk('.'):
    for name in files:
        p=str(name).find('.')
        suf=name[p:]
        if root == '.' and (suf=='.in' or suf=='.out' or suf=='.ans'):
            if suf=='.ans': out_suf = 'ans'
            if firstsuf == 'unknown': firstsuf = suf
            if suf == firstsuf: tot += 1
            if not cnt.__contains__(suf): cnt[suf] = 0
            cnt[suf] += 1
            newname = pre+str(cnt[suf])+suf
            shutil.move(name, newname)
            print(root, newname, name)

for i in range(n_ex_tests):
    with open('.\\ex_'+pre+str(i+1)+'.'+in_suf, 'w') as f:
        f.write('')
    with open('.\\ex_'+pre+str(i+1)+'.'+out_suf, 'w') as f:
        f.write('')        

with open('.\\problem.conf', 'w') as f:
    f.write('n_tests '+str(tot)+'\n')
    f.write('n_ex_tests '+str(n_ex_tests)+'\n')
    f.write('n_sample_tests '+str(n_sample_tests)+'\n')
    f.write('input_pre '+pre+'\n')
    f.write('output_pre '+pre+'\n')
    f.write('input_suf '+in_suf+'\n')
    f.write('output_suf '+out_suf+'\n')
    f.write('time_limit '+str(time_limit)+'\n')
    f.write('memory_limit '+str(memory_limit)+'\n')
    f.write('output_limit '+str(output_limit)+'\n')
    f.write('use_builtin_judger on\n')
    f.write('use_builtin_checker ncmp')

包含subtask(数据放在子文件夹下)

import os, shutil

subtasks = {}
cnt = {}
tot = 0
firstsuf = 'unknown'
pre = 'data'
in_suf, out_suf = 'in', 'out'
path=os.getcwd()

for root, dirs, files in os.walk('.'):
    for name in files:
        p=str(name).find('.')
        suf=name[p:]
        if root[-8:-1]=='subtask' and (suf=='.in' or suf=='.out' or suf=='.ans'):
            if (suf=='.ans'): out_suf = 'ans'
            if firstsuf == 'unknown': firstsuf = suf
            if not subtasks.__contains__(root): subtasks[root]=0
            if not cnt.__contains__(suf): cnt[suf] = 0
            cnt[suf]+=1
            if suf==firstsuf: subtasks[root]+=1
            newname=pre+str(cnt[suf])+suf
            shutil.copyfile(os.path.join(root,name), os.path.join(path, newname))
            print(root, firstsuf, subtasks[root], name)

with open('.\\problem.conf', 'w') as f:
    f.write('n_subtasks '+str(len(subtasks))+'\n')
    i=1
    for key,val in subtasks.items():
        tot+=val
        print(key, val, tot)
        f.write('subtask_end_'+str(i)+' '+str(tot)+'\n')
        f.write('subtask_score_'+str(i)+' 0\n')
        i+=1
    f.write('n_tests '+str(tot)+'\n')
    f.write('n_ex_tests 0\n')
    f.write('n_sample_tests 0\n')
    f.write('input_pre '+pre+'\n')
    f.write('output_pre '+pre+'\n')
    f.write('input_suf '+in_suf+'\n')
    f.write('output_suf '+out_suf+'\n')
    f.write('time_limit 1\n')
    f.write('memory_limit 128\n')
    f.write('output_limit 64\n')
    f.write('use_builtin_judger on\n')
    f.write('use_builtin_checker ncmp')

Atcoder的数据

Atcoder数据下载地址

import os, shutil

cnt = {}
tot = 0
pre = 'data'
firstsuf = 'unknown'
in_suf, out_suf = 'in', 'out'
time_limit = 1
memory_limit = 256
output_limit = 64
n_ex_tests = 1
n_sample_tests = 1

for dirname, subdirs, files in os.walk('.'):
    for subdir in subdirs:
        for subdirname, subdirs, files in os.walk(os.path.join(dirname,subdir)):
            for name in files:
                p=str(name).find('.')
                suf=name[p:]
                if subdirname == '.\\in': suf = '.in'
                if subdirname == '.\\out': suf = '.out'
                if firstsuf == 'unknown': firstsuf = suf
                if suf == firstsuf: tot += 1
                if not cnt.__contains__(suf): cnt[suf] = 0
                cnt[suf] += 1
                newname = pre+str(cnt[suf])+suf
                shutil.move(subdirname+'/'+name, dirname+'/'+newname)
                print(subdirname, newname, name)

for i in range(n_ex_tests):
    with open('.\\ex_'+pre+str(i+1)+'.'+in_suf, 'w') as f:
        f.write('')
    with open('.\\ex_'+pre+str(i+1)+'.'+out_suf, 'w') as f:
        f.write('')        

with open('.\\problem.conf', 'w') as f:
    f.write('n_tests '+str(tot)+'\n')
    f.write('n_ex_tests '+str(n_ex_tests)+'\n')
    f.write('n_sample_tests '+str(n_sample_tests)+'\n')
    f.write('input_pre '+pre+'\n')
    f.write('output_pre '+pre+'\n')
    f.write('input_suf '+in_suf+'\n')
    f.write('output_suf '+out_suf+'\n')
    f.write('time_limit '+str(time_limit)+'\n')
    f.write('memory_limit '+str(memory_limit)+'\n')
    f.write('output_limit '+str(output_limit)+'\n')
    f.write('use_builtin_judger on\n')
    f.write('use_builtin_checker ncmp')

todo

把代码改成参数的形式(感觉要永远鸽了)

posted @ 2019-04-12 19:09  naiij  阅读(756)  评论(1编辑  收藏  举报