zoukankan      html  css  js  c++  java
  • 将内容输入到文本中、读取文件、将输出结果保存到文件中、计算程序跑的时间(c++)

    将数据输出到文件中

    #include<iostream>
    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<cmath>
    #include<vector>
    #include<map>
    #include<cstdlib>
    #include<fstream>
    #include<time.h>
    using namespace std;
    typedef long long LL;
    const LL mod=1e9+7;
    const LL INF=1e9+7;
    const int maxn=1e5+50;
    int a[maxn],b[maxn];//存已经出现过的数 和 没有出现过的数
    int main()
    {
        srand((unsigned)time(0));//保证随机函数每次跑出来结果都不一样
        ofstream filein;//
        filein.open("a.txt");
        int T;
        T=rand()%3+1;
        filein<<T<<'
    ';
        return 0;
    }

    读取文件中的内容,将输出结果存到文件中

        freopen("input8.txt", "r",stdin);
        freopen("output8.txt", "w", stdout);

     计算程序跑的时间,放在main函数开头和结尾:加头文件ctime


    int main()
    {
      clock_t start,finish;
    double totaltime; start=clock(); ....中间是代码 finish=clock(); totaltime=(double)(finish-start)/CLOCKS_PER_SEC; cout<<"此程序的运行时间为"<<totaltime<<"秒!"<<endl;
    }
    当初的梦想实现了吗,事到如今只好放弃吗~
  • 相关阅读:
    Spark Streaming 的容错
    Master 接受其它组件的注册
    Spark Context 概述
    Python 使用random模块生成随机数
    Python 中print 和return 的区别
    Python 访问字典(dictionary)中元素
    PIL:处理图像的好模块
    2.线性回归
    3.梯度下降法
    4.pca与梯度上升法
  • 原文地址:https://www.cnblogs.com/caijiaming/p/11613076.html
Copyright © 2011-2022 走看看