作为一个搞oi的,cena的用处还是很大的,以下是一个关于自定义校验器的模板,使用时需要放在data文件夹下,要有exe文件。
代码方面感谢wyl8899 ORZ.
#include<cstdio> #include<cstdlib> FILE *fscore,*freport,*fstd,*fin,*fout; bool Judge() { double x,y,dif; fscanf(fstd,"%lf",&x); fscanf(fout,"%lf",&y); dif=(x>y)?(x-y):(y-x); fprintf(freport,"Std:%.10lf\nYour Ans:%.10lf\nDiffer:%.10lf\n",x,y,dif); return dif<=0.000001; } int main(int argc,char *argv[]) { fscore=fopen("score.log","w");//打开得分文件 freport=fopen("report.log","w");//打开报告文件 fstd=fopen(argv[2],"r");//打开测试点标准输出文件 int score=atoi(argv[1]);//取得测试点的分数 fin=fopen("elephant.in","r");//打开测试点标准输入文件 fout=fopen("elephant.out","r");//打开用户的数据输出文件 if (!fout) { fprintf(fscore,"%d",0);//返回0分 fprintf(freport,"no output");//报告Judge结果为no output } else if (Judge())//Judge后结果为真 { fprintf(fscore,"%d",score);//返回满分 fprintf(freport,"right");//报告Judge结果为right } else { fprintf(fscore,"%d",0);//返回0分 fprintf(freport,"wrong");//报告Judge结果为wrong } fclose(fscore);//关闭得分文件 fclose(freport);//关闭报告文件 return 0; }