腳本程序基於Python3.4,請先配置好環境。
import os
def run():
# 運行程序並輸出結果
os.system('my.exe < in.txt > my.dat')
os.system('right.exe < in.txt > right.dat')
def check():
# 逐行對比運行結果
my = open('my.dat', 'r')
right = open('right.dat', 'r')
log = open('log.txt', 'w')
log.write('-----------All Error-----------\n')
for (i, (a, b)) in enumerate(zip(my, right)):
if a != b:
log.write('line ' + str(i+1) + '\n')
log.write('---MY:' + a)
log.write('---AC:' + b)
if __name__ == '__main__':
run()
check()
in.txt------數據輸入文件
my.exe----你的程序
right.exe--AC的程序
my.dat----你的程序的輸出
right.dat--AC程序的輸出
log.txt----輸出結果對比