zoukankan      html  css  js  c++  java
  • ACM 程序对拍

    1.首先是要有一个产生数的程序,将产生的数据保存在data.txt中。

    产生int型小数

    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<time.h>
    int main() {
        freopen("data.txt", "w", stdout);
        srand(time(NULL));
        //通过控制t的大小控制产生数的范围,控制n可以控制数据的产生量。
        int t, n = 1000;
        while(n--) {
            printf("%d
    ",rand()%t);
        }
        return 0;
    }
    

    产生随机的两位小数

    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<time.h>
    int main() {
        freopen("data.txt", "w", stdout);
        srand(time(NULL));
        int n = 1000;
        while(n--) {
            printf("%.2lf
    ",rand()*1.0/100);
        }
        return 0;
    }
    

    产生字符串

    #include<cstdio>
    #include<cstdlib>
    #include<cstring>
    #include<time.h>
    int main() {
        freopen("data.txt", "w", stdout);
        srand(time(NULL));
        int t, n = 1000;
        while(n--) {
            printf("%c
    ",rand()%26 + 'A');
        }
        return 0;
    }
    

    相对于所需要的数据在这个基础上修改就可以了。

    2.在你的程序与已经AC的程序上分别加上

    freopen( "data.txt","r",stdin );
    freopen( "1.txt","w",stdout );
    freopen( "data.txt","r",stdin );
    freopen( "2.txt","w",stdout );
    为了方便查找不同的测试数据,建议把读入的数据一并输出,方便查看。

    3.在保存数据的位置新建一个文本文档

    内容是

    fc out1.txt out2.txt 

    pause

    并把文本的扩展名改为.bat,点击运行就可以查看不同的测试数据了。

    例如:

    #include <stdio.h>
    int main() {
        freopen( "data.txt","r",stdin );
        freopen( "1.txt","w",stdout );
        int a, b;
        while (scanf("%d%d", &a, &b) != EOF) {
            printf("%d %d ", a, b);
            printf("%d
    ", a + a);
        }
        return 0;
    }
    

    #include <stdio.h>
    int main() {
        freopen( "data.txt","r",stdin );
        freopen( "2.txt","w",stdout );
        int a, b;
        while (scanf("%d%d", &a, &b) != EOF) {
            printf("%d %d ", a, b);
            printf("%d
    ", a + b);
        }
        return 0;
    }
    

    进行对拍会显示

    显示不同的数据就可以拿来用了


  • 相关阅读:
    zip压缩类
    sqlserver配置允许快照隔离
    (三)装饰模式
    (二)策略模式
    (一)简单工厂模式
    MFC中lib和dll的区别
    VC MFC工具栏(CToolBar)控件(非常重要)
    CMFCMenuBar和CMFCToolBar相同ID,在显示不同标签文字
    CImageList类Create函数参数解析
    c++连接数据库代码
  • 原文地址:https://www.cnblogs.com/cniwoq/p/6770918.html
Copyright © 2011-2022 走看看