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;
    }
    

    进行对拍会显示

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


  • 相关阅读:
    关于SQL Server中的DateTime类型和C#中的DateTime类型的一点小记录
    强类型DataSet的使用简明教程2
    byte[]转string的感悟
    ArrayList的Insert方法
    FormsAuthenticationTicket对象
    powerdesigner设置唯一键,但不是主键的方式
    KeyValuePair用法(转)
    如何在安装过程中部署DevExpress控件
    asp.net GridView手写事件,包括取主键、取值、更新、选择、删除
    序列化(Serialize)、反序列化(Deserialize)
  • 原文地址:https://www.cnblogs.com/cniwoq/p/6770918.html
Copyright © 2011-2022 走看看