先上代码:
/*
checker.cpp
Copyright 2018 (c) WCIoQM&RA
作者:张子辰
邮箱:zichen350@gmail.com
建议的编译指令:g++.exe checker.cpp -o checker.exe -std=gnu++11 -O2
*/
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string>
#include <sys/time.h>
#define System system
using namespace std;
int main()
{
string name;
string command = " -Wl,--stack=2147483648 -Wall";
char tmp; string tmp2;
int n;
puts("Input problem name:");
cin
>> name;
string namein = name + ".in", nameout = name + ".out";
puts("Input the number of the test data:");
cin
>> n;
puts("Enable O2 Optimization?(Y/N)");
cin
>> tmp;
if (tmp == 'Y' || tmp == 'y')command += "
-O2";
puts("Language standard?(GNU++98/GNU++11/GNU++14/GNU++17)");
cin
>> tmp2;
for (int i = 0; i<tmp2.length(); i++)if (tmp2[i] >= 'A'&&tmp2[i] <= 'Z')tmp2[i] += 32;
if (tmp2 != "gnu++11"&&tmp2 != "gnu++14"&&tmp2 != "gnu++17")tmp2 = "gnu++98";
command
+= " -std=" + tmp2;
System(("g++.exe " + name + ".cpp" + " -o " + name + ".exe" + command).c_str());
long long times = 0;
long long total = 0;
struct timeval start, end;
for (int i = 1; i <= n; i++)
{
string name2 = name + to_string(i);
string name2out = name2 + ".out", name2in = name2 + ".in";
System(("ren " + name2in + " " + namein).c_str());
gettimeofday(&start, NULL);
System((".\\" + name).c_str());
gettimeofday(&end, NULL);
times
= 1000000 * (end.tv_sec - start.tv_sec) + end.tv_usec - start.tv_usec;
total
+= times;
cout
<< "Test " << i << ": " << times / 1000.0 << "ms" << endl;
System(("fc " + nameout + " " + name2out).c_str());
System(("ren " + namein + " " + name2in).c_str());
}
cout
<< "Total: " << total / 1000.0 << "ms" << endl;
return 0;
}
说明:目前只能对拍传统题,只支持C++,problem.cpp 对应的输入文件为problem.in,输出文件为problem.out,答案文件的格式为problem%d.in和problem%d.out,答案匹配模式为字符串匹配(过滤文件末位空行,但不过滤行末空格)。对拍时,请将对拍脚本、答案文件、程序文件放在同一目录下。
如对对拍脚本的使用方法有任何疑问,请在评论区留言。
如发现对拍脚本的漏洞,亦欢迎读者批评指正。
没有评论:
发表评论