├── README.md ├── globalvar.py └── outputgen.py /README.md: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /globalvar.py: -------------------------------------------------------------------------------- 1 | global cmdproglue,path,problempath 2 | cmdproglue = ''' 3 | #!/bin/bash 4 | PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin 5 | export PATH 6 | ''' 7 | problempath = "/home/kid/OG/problist" 8 | shellpath = "/home/kid/OG/" 9 | path = problempath+"/code_file/" 10 | newdir = problempath + "/DB/" 11 | programtype = dict() 12 | -------------------------------------------------------------------------------- /outputgen.py: -------------------------------------------------------------------------------- 1 | import subprocess,os,sys,stat 2 | from globalvar import * 3 | # coding=utf8 4 | 5 | 6 | def getdata(number): 7 | datastream = "" 8 | f = open(problempath+"/file/"+str(number)+".in","r") 9 | for line in f: 10 | datastream += line 11 | f.close() 12 | return datastream 13 | 14 | def get_dir_and_file(path,id): 15 | exe = list() 16 | p = str( path ) 17 | if p=="": 18 | return [ ] 19 | # p = p.replace( "/","\\") 20 | if p[-1] != "/": 21 | p = p+"/" 22 | # print(p) 23 | dic = os.listdir( p ) # list file in this path(dir) 24 | for d in dic: 25 | if d == str(id) and os.path.isdir( p + d ): 26 | #print(p + d) 27 | file = os.listdir( p + d ) 28 | p = p + d + "/" 29 | for f in file : 30 | if os.path.isfile( p + f ): # check is file or not 31 | # spilt filename and file extenion 32 | fname , fext = os.path.splitext(f) 33 | if fext == ".exe": 34 | exe.append( p + f ) 35 | if fext == ".class": 36 | exe.append( fname ) 37 | return exe 38 | 39 | def check_output(ofile,pid): 40 | Max = 0 41 | tmplist = list() 42 | # output = "" 43 | for k in ofile.keys(): 44 | # print("key:",k,"value:",ofile[k]) 45 | tmplist.append(k) 46 | tmplist.sort() 47 | while tmplist: 48 | if ofile[tmplist[0]] > Max : 49 | output = tmplist[0] 50 | Max = ofile[tmplist[0]] 51 | tmplist.pop(0) #del the first item 52 | del tmplist 53 | print(output) 54 | 55 | def main(a): 56 | ofile = dict() 57 | data = getdata(a[1]) 58 | # print(data) 59 | exe = get_dir_and_file(problempath+"/DB/",a[1]) 60 | exe.sort() 61 | for e in exe: 62 | ename , eext = os.path.splitext(e) 63 | ############################### process on ################################ 64 | if eext == ".exe": 65 | p = subprocess.Popen(e, stdin = subprocess.PIPE,stdout = subprocess.PIPE, stderr = subprocess.PIPE, shell = True) 66 | else: 67 | javafile = open(shellpath+"exejava.sh","w") 68 | javafile.write(cmdproglue) 69 | javafile.write("cd "+problempath+"/DB/"+a[1]+"\n") 70 | javafile.write("java "+ e + "\n") 71 | javafile.close() 72 | p = subprocess.Popen(["sh",shellpath+"exejava.sh"], stdin = subprocess.PIPE,stdout = subprocess.PIPE, stderr = subprocess.PIPE, shell = False) 73 | ####################### process end and get output ######################## 74 | ############# p.communicate return (stdout , stderr) ################# 75 | try: 76 | std = p.communicate(input = data.encode('utf-8') ,timeout = 10) 77 | o =std[0].decode('utf-8','ignore') 78 | if o in ofile: 79 | ofile[o] += 1 80 | else : 81 | ofile[o] = 1 82 | #p.terminate() 83 | except: 84 | p.kill() 85 | check_output(ofile,a[1]) 86 | # print(ofile) 87 | del ofile 88 | del exe 89 | 90 | if __name__ == "__main__": 91 | main(sys.argv) 92 | 93 | --------------------------------------------------------------------------------