最簡單的對拍程式(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;
}