对拍

· · 算法·理论

Masonの对拍

朴素考场对拍

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
int main() {
    for (int i = 1;i <= 100;i++) {
        system("gen > test.in.txt");
        system("test1.exe < test.in.txt > a.out.txt");
        system("test2.exe < test.in.txt > b.out.txt");
        std::cout<<i<<"small\n";
        if (system("fc a.out.txt b.out.txt")) {
            system("pause");
            return 0;
        }
    }
}

小数据+大数据对拍

#include <stdio.h>
#include <stdlib.h>
#include <iostream>
int main() {
    for (int i = 1;i <= 100;i++) {
        system("gen1 > test.in.txt");
        system("test1.exe < test.in.txt > a.out.txt");
        system("test2.exe < test.in.txt > b.out.txt");
        std::cout<<i<<"small\n";
        if (system("fc a.out.txt b.out.txt")) {
            system("pause");
            return 0;
        }
    }
    for (int i = 1;i <= 50;i++) {
        system("gen2 > test.in.txt");
        system("test1.exe < test.in.txt > a.out.txt");
        system("test2.exe < test.in.txt > b.out.txt");
        std::cout<<i<<"big\n";
        if (system("fc a.out.txt b.out.txt")) {
            system("pause");
            return 0;
        }
    }
}

BEAUTIFUL の 对拍

#include <bits/stdc++.h>
using namespace std;
void printf_green(const char *s)
{
    printf("\033[0m\033[1;32m%s\033[0m", s);
}

void printf_red(const char *s)
{
    printf("\033[0m\033[1;31m%s\033[0m", s);
}

bool check()
{
    string ans,ans2;
    freopen("a.out.txt","r",stdin);
    char c;
    while(scanf("%c",&c)!=EOF) ans+=c;
    fclose(stdin);
    freopen("b.out.txt","r",stdin);
    while(scanf("%c",&c)!=EOF) ans2+=c;;
    fclose(stdin);
    return ans == ans2;
}
int main() {
    for(int i = 1; i <= 500;i++) {
        system("gen > test.in.txt");
        system("test1.exe < test.in.txt > a.out.txt");
        system("test2.exe < test.in.txt > b.out.txt"); 

        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{
            printf_red("WA on test ");
            string a = to_string(i);
            char ch[1000];
            strcpy(ch, a.c_str());
            printf_red(ch);
            cout<<"\n";
            return 0;
        }
    }
    printf_green("ALL TESTS RIGHT");
}