八中OJ的SPJ模板
BSGS的严格根号算法

JDFZOJ的SPJ模板

shinbokuow posted @ Aug 19, 2015 09:21:46 AM in Something with tags 奇怪の姿势 SPJ , 1152 阅读

 

#include <cstdio>
#include <cstring>
#include <cmath>
#define OJ_AC 0
#define OJ_WA 1
bool dcmp(double x, double y)
{
	return fabs(x-y) <= fabs(y*0.05);
}
char *daStr;
void diff(double R, double Wa)
{
	FILE *out = fopen("diff.out", "a+");//错误详情文件,a+是append追加方式
	fprintf(out, "====================%s\n", daStr);
	fprintf(out, "Right : %lf\n", R);
	fprintf(out, "--------------------\n");
	fprintf(out, "Your : %lf\n", Wa);
	fprintf(out, "====================\n");
	fclose(out);
}
int main(int argc, char* argv[]){
	FILE *fo, *fu, *fi;
	double a, b;
	daStr = strrchr(argv[1], '/');//测试点文件名
	fi = fopen(argv[1], "r");//测试点输入文件 in
	fo = fopen(argv[2], "r");//测试点输出文件 out
	fu = fopen(argv[3], "r");//用户答案文件 user
	int N, S1, S2;
	fscanf(fi, "%d", &N);
	fclose(fi);
	for(int i=0; i<N; ++i)
	{
		S1 = fscanf(fo, "%lf", &a);
		S2 = fscanf(fu, "%lf", &b);
		if(S1 != 1 || S2 != 1 || !dcmp(b, a))
		{
			diff(a, b);//显示可查看的错误信息
			fclose(fo);
			fclose(fu);
			return OJ_WA;
		}
	}
	fclose(fo);
	fclose(fu);
	return OJ_AC;
}

登录 *


loading captcha image...
(输入验证码)
or Ctrl+Enter