对拍
可以选择对拍次数的对拍程序( 表示执行 次,其他数 表示执行次)
这是我的对拍代码,请参考:
#include <stdio.h>
#include<iostream>
#include <stdlib.h>
using namespace std;
int main() {
int n;
cin>>n;
for(int i = 1; n?i<=n:1;i++) {
system("gen > test.in");
system("sol.exe < test.in > a.out"); //sol:要对的程序
system("ans.exe < test.in > b.out"); //ans:保证对的暴力代码
cout<<i<<endl;
if (system("fc a.out b.out")) {
system("pause");
return 0;
}
}
cout<<"AC";
}v2
#include <bits/stdc++.h>
using namespace std;
void printf_green(const char *s)
{
printf("\033[0m\033[1;32m%s\033[0m", s);
}
bool check()
{
string ans,ans2;
freopen("a.out","r",stdin);
char c;
while(scanf("%c",&c)!=EOF) ans+=c;
fclose(stdin);
freopen("b.out","r",stdin);
while(scanf("%c",&c)!=EOF) ans2+=c;;
fclose(stdin);
return ans == ans2;
}
int main() {
int n;
cin>>n;
for(int i = 1; n?i<=n:1;i++) {
system("gen > test.in");
system("sol.exe < test.in > a.out");
system("ans.exe < test.in > b.out");
if (check()) {
printf_green("AC on test ");
string a = to_string(i);
char ch[1000];
strcpy(ch,a.c_str());
printf_green(ch);
cout<<"\n";
}
else{
cout<<"WA!!!!"<<endl;
return 0;
}
}
printf_green("ALL TESTS RIGHT");
}V3
#include <bits/stdc++.h>
#include<windows.h>
using namespace std;
void printf_green(const char *s)
{
printf("\033[0m\033[1;32m%s\033[0m", s);
}
BOOL SetConsoleColor(WORD wAttributes)
{
HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
if (hConsole == INVALID_HANDLE_VALUE)
return FALSE;
return SetConsoleTextAttribute(hConsole, wAttributes);
}
bool check()
{
string ans,ans2;
freopen("a.out","r",stdin);
char c;
while(scanf("%c",&c)!=EOF) ans+=c;
fclose(stdin);
freopen("b.out","r",stdin);
while(scanf("%c",&c)!=EOF) ans2+=c;;
fclose(stdin);
return ans == ans2;
}
int main() {
int n;
cin>>n;
for(int i = 1; n?i<=n:1;i++) {
system("gen > test.in");
system("sol.exe < test.in > a.out");
system("ans.exe < test.in > b.out");
if (check()) {
SetConsoleColor(FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | BACKGROUND_GREEN);
printf("[AC in %d]",i);
cout<<"\n";
}
else{
SetConsoleColor(FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE | BACKGROUND_RED);
printf("[WA in %d]",i);
return 0;
}
}
printf_green("ALL TESTS RIGHT");
}