最简单的对拍程序(A + B Problem)
造数据 make.cpp:
#include <bits/stdc++.h> using namespace std; int main() { srand(time(0)); printf("%d %d ", 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 ", 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 ", a + b + 1); else printf("%d ", 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 "); break; } else printf("Accepted "); } return 0; }
不用c++的duipai.bat:将system(""); 里面的东西放进 .bat 里面。(Windows脚本)
------------恢复内容结束------------