天天看点

对拍

最简单的对拍程序(A + B Problem)

造数据 make.cpp:

#include <bits/stdc++.h>
using namespace std;

int main()
{
    srand(time(0));
    printf("%d %d\n", rand() % 100000, rand() % 100000);
    return 0;
}      

正解 std.cpp

#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a, b;
    scanf("%d%d", &a, &b);
    printf("%d\n", a + b);
    return 0;
}      

待对拍程序 code.cpp

#include <bits/stdc++.h>
using namespace std;

int main()
{
    srand(time(0));
    int a, b;
    scanf("%d%d", &a, &b);
    if(rand() % 10 == 0) printf("%d\n", a + b + 1);
    else printf("%d\n", a + b);
    return 0;
}      

对拍程序 duipai.cpp

#include <iostream>
#include <algorithm>
using namespace std;

int main()
{
    int t = 0;
    while(true)
    {
        printf("test #%d: ", ++ t); //Linux为./make  ./std  ./code  diff
        system("make.exe > data.in");
        system("std.exe < data.in > data.ans");
        system("code.exe < data.in > data.out");
        if(system("fc data.out data.ans > data.log")) {
            printf("Wrong Answer\n");
            break;
        }
        else printf("Accepted\n");
    }
    return 0;
}      
上一篇: 对拍
下一篇: 对拍

继续阅读