c++對拍程式

lbperfect123發表於2020-09-26
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<windows.h>
using namespace std;
int main()
{
	int ok=0;
	int n=50;
    for(int i=1; i<=n; ++i)
    {
        system("make.exe > make.txt");
        system("ccpc.exe < make.txt > ccpc.txt");
        double begin=clock();
        system("baoli.exe < make.txt > baoli.txt");
        double end=clock();
        double t=(end-begin);
       
        if(system("fc ccpc.txt baoli.txt"))
        {
            printf("測試點#%d ",i);
        	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED);
        	printf("Wrong Answer\n");
        	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |  FOREGROUND_RED |FOREGROUND_GREEN | FOREGROUND_BLUE);
        	
        	
        }
        else if(t>1000) //1秒
        {
        	printf("測試點#%d ",i);
        	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_RED |FOREGROUND_GREEN);
        	printf("TLE");
        	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |  FOREGROUND_RED |FOREGROUND_GREEN | FOREGROUND_BLUE);
        	printf(" 用時%.0lfms\n",t); 
           
        }
        else
        {
        	printf("測試點#%d ",i);
        	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY | FOREGROUND_GREEN);
        	printf("Accepted");
        	SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_INTENSITY |  FOREGROUND_RED |FOREGROUND_GREEN | FOREGROUND_BLUE);
        	printf(" 用時%.0lfms\n",t); 
        	ok++; //AC數量+1
		} 
		Sleep(1000);
    }
    cout<<endl;
    double res=100.0*ok/n;
    printf("共 %d 組測試資料,AC資料 %d 組。 得分%.1lf。",n,ok,res);
}

對拍程式主要獲得的是3個部分的資料 : make.exe  std.exe  和baoli.exe make.exe是資料生成器,將exe跑入到暴力和std中從而可以進行資料的對比 每次延時1s便於找出錯誤資料

相關文章