zoukankan      html  css  js  c++  java
  • 【模板】对拍程序

    前言

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

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

    配套的是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
    ",t-s);
            }while(1);
            printf("WA time: %ldms
    ",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效果

    “Make my parents proud,and impress the girl I like.”
  • 相关阅读:
    js 监听页面url锚点变化 window.onpopstate
    js 返回上一页并刷新页面
    table 会有默认的外边框,内部会有分割线
    javascript 中设置window.location.href跳转无效问题解决办法
    chrom控制台常用方法
    Acquire and Release Fences
    常用 git 命令
    vim版本更新
    vim bundle安装
    emacs 常用命令
  • 原文地址:https://www.cnblogs.com/NSD-email0820/p/9742810.html
Copyright © 2011-2022 走看看