码迷,mamicode.com
首页 > 其他好文 > 详细

【模板】对拍程序

时间:2018-10-04 19:30:23      阅读:1518      评论:0      收藏:0      [点我收藏+]

标签:image   ...   配套   clu   png   pac   include   space   and   

前言

考试都考了几十套了,一直都没有对拍过,贪心题要么就写不出来,要么就手动造几个数据拍一下。

今天心情不很好,不怎么想写题,就到处扒了我觉得稍微好看一点儿也好背一点儿的对拍。

配套的是a+b代码和数据生成代码,可以试用一下。随机数据生成比较水,我还没研究过,但是能用也就将就了吧。

我几乎敲了5遍才背下来这段对拍...

代码

对拍程序

库函数不能省

#include<cstdio>
#include<cstdlib>
#include<ctime>
int main()
{
    long s,t;
    while(1)
    {
        system("cls");
        do{
            system("data > try.in");//数据生成程序 
            s=clock();
            system("a < try.in > try1.out");//正解 
            t=clock();
            system("b < try.in > try2.out");//暴力 
            if(system("fc try1.out  try2.out > nul"))break;
            else printf("AC time: %ldms\n",t-s);
        }while(1);
        printf("WA time: %ldms\n",t-s);
        system("fc try1.out try2.out");
        system("pause > nul");
    }
}

正解

#include<iostream>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    cout<<a+b<<endl;
    return 0;
}

暴力

#include<iostream>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    while(b--) a++;
    cout<<a<<endl;
    return 0;
}

随机数据生成

#include<iostream>
#include<ctime>
#include<cstdlib>
using namespace std;
int main()
{
    srand((unsigned)time(0));
    int a,b;
    a=rand();
    b=rand();
    cout<<a<< <<b<<endl;
    return 0;
}

运行结果

AC效果

技术分享图片

WA效果

技术分享图片

 

【模板】对拍程序

标签:image   ...   配套   clu   png   pac   include   space   and   

原文地址:https://www.cnblogs.com/NSD-email0820/p/9742810.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!