使用说明:
linux下需要编译
这里使用duipai.cpp程序来对拍的,没有用bash脚本
使用时,先编译4个文件(ac中放正确的标程/暴力程序 wa中自己的程序 rand是用来产生数据的)
g++ duipai.cpp -o duipai
g++ rand.cpp -o rand
g++ ac.cpp -o ac
g++ wa.cpp -o wa
然后运行duipai即可
./duipai
duipai.cpp 对拍程序
///对拍文件,需要在另外三个文件编译后才可运行
///windows下生成.EXE可执行文件,文件都放在同一文件夹下用文中给的相对路径即可
#include<bits/stdc++.h>
using namespace std;
int main(){
int Case=1;
while(1){
printf("The result of No. %d Case is: ",Case=1);
system("rand"); ///windows不加"./",linux下需要在可执行文件的文件名前加"./"
system("ac"); ///system("./***"); 运行程序,其中***代表可执行文件名
system("wa");
if (system("fc ac.out wa.out")){ ///windows 下用 system("fc *** ***");
printf("Wrong Answer\n"); ///linux 环境用 system("diff *** ***");
return 0; ///比较两个文件,我们在对拍时比较两个不同程序的输出文件
}
else printf("Accepted\n");
}
return 0;
}
rand.cpp 随机数生成程序,需自己造随机生成数据
#include<bits/stdc++.h>
using namespace std;
#define random(a,b) ((a)+rand()%((b)-(a)+1))
stringstream ss;
int main( int argc, char *argv[] ){
freopen("data.in","w",stdout);
int seed=time(NULL);
if(argc){
ss.clear();
ss<<argv[1];
ss>>seed;
}
srand(seed);
//以上为随机数初始化,请勿修改
//random(a,b)生成[a,b]的随机整数
//以下写你自己的数据生成代码
int n=5;
printf("%d\n",n);
for(int i=0 ; i<n ; ++i){
printf("%d ",random(0,10));
}
printf("\n");
return 0;
}
ac.cpp 暴力求解的超时标程
#include<bits/stdc++.h>
using namespace std;
int main(){
freopen("data.in","r",stdin);
freopen("ac.out","w",stdout);
int n,x;
cin >> n;
int ans(0);
while (n--){
cin >> x;
if (x > 6) ans++;
}
cout << ans << endl;
return 0;
}
wa.cpp 自己的错误程序
#include<bits/stdc++.h>
using namespace std;
int main(){
freopen("data.in","r",stdin);
freopen("wa.out","w",stdout);
int n,x;
cin >> n;
int ans(0);
while(n--){
cin >> x;
if (x >= 6) ans++;
}
cout << ans << endl;
return 0;
}
随机数和标程一定要造好!!!