hustoj使用special judge

spj是一个程序,它可以读取测试输入,测试输出,用户输出来进行答案的正确性判断,spj返回0代表答案正确,返回其他值代表答案错误

下面是一个判断精度的例子

样例输入
2 //T代表组数
50 
100
样例输出
Case 1: 12.9933758002
Case 2: 8.5431270393
用户输出
Case 1: 12.9933758005
Case 2: 8.5431270397

spj.cpp代码

#include <bits/stdc++.h>

const double eps = 1e-6;

int main(int argc, char *args[]) {
    freopen("diff.out", "w", stdout);//这句话可以让spj的输出在wa对比中显示

    FILE *f_in = fopen(args[1], "r");//测试输入
    FILE *f_out = fopen(args[2], "r");//测试输出
    FILE *f_user = fopen(args[3], "r");//用户输出

    int ans = 0;
    int T;
    fscanf(f_in, "%d", &T);//使用fscanf读入
    for (int i = 1; i <= T; i++) {
        int user_id, std_id;
        double user_ans, std_ans;
        fscanf(f_user, "Case %d: %lf", &user_id, &user_ans);
        fscanf(f_out, "Case %d: %lf", &std_id, &std_ans);
        if (user_id != std_id) {
            printf("%d: id is wrong\n", i);
            ans = 1;
        }
        if (fabs(user_ans - std_ans) > eps) {
            printf("%d: ans is wrong\n", i);
            ans = 1;
        }
    }

    return ans;//建议统一出口,方便显示wa对比
}

写完后和数据上传到一个文件夹,进行编译运行测试

g++ -o spj spj.cpp
./spj sample.in sample.out sample.out
echo $?
0 #Accepted
./spj sample.in sample.out sample.in
echo $?
1 #Wrong Answer

留下评论

电子邮件地址不会被公开。 必填项已用*标注