[C++] 对拍模板
共需内容:
- create.exe 数据生成器
- match.exe 匹配程序
- check.exe 正解
- test.exe 测试程序
以 A+B Problem 为例示范:
create.cpp
#include<bits/stdc++.h>
using namespace std;
#define rand(a,b) rand()%((b)-(a)+1)+(a)
int main(){
struct _timeb T;
_ftime(&T);
srand(T.millitm);
cout<<rand(1,32767)<<" "<<rand(1,32767);
}
match.cpp
#include<bits/stdc++.h>
#include<windows.h>
using namespace std;
int main(){
cout<<"Test number >>";
int cases;
int tl;
cin>>cases;
cout<<"Time Limit (ms) >>";
cin>>tl;
int cr=0;
for(int c=1;c<=cases;++c){
cout<<"Test "<<c<<endl;
system("create.exe > test.txt");
system("check.exe < test.txt > check.txt");
int start=clock();
system("test.exe < test.txt > answer.txt");
int end=clock();
cout<<"Finished in "<<end-start<<" ms."<<endl;
if(system("fc check.txt answer.txt")){
cout<<"Wrong Answer"<<endl;
system("pause");
}
else if(end-start>tl){
cout<<"TimeLimitedExceed"<<endl;
system("pause");
}
else{
cout<<"Accept"<<endl;
cr++;
}
cout<<endl<<endl<<endl;
}
cout<<"Test Over"<<endl;
cout<<"Total correct : "<<cr<<" / "<<cases<<endl;
system("pause");
}