c++对拍程序

#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便于找出错误数据

©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页