zoukankan      html  css  js  c++  java
  • 第二章,循环结构,输入输出,clock

    计时

    1. 计时函数: clock()
    2. 返回目前为止运行的时间
    3. 注意要除以常数 CLOCKS_PER_SEC, 才能得到以秒为单位。
    4. 头文件 time.h

    管道

    1. 在windows命令行下执行echo 20|abc,操作系统会自动把20输入,其中abc为程序名。

    输入输出框架

    1. scanf:空格 TAB和回车都是无关紧要的,所以按enter键不意味着输入的结束。
    2. Windows下,输入完毕之后先按enter,再按ctrl+z,最后再按enter就可以结束输入。
    3. linux下,输入完毕后按ctrl+D即可。
    4. 输入输出重定向
      1.   main的入口处加两个语句
      2. freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
      3. 注意看题目有没有规定能否重定向,有没有规定文件名。
    5. #define LOCAL
      ...
      #ifdef LOCAL
      ...
      #endif
    6. fopen版本
      1. 若禁止重定向,那就可以用fopen..
      2. 用fopen和fscanf/fprintf进行输入输出
      3. #include<stdio.h>
        #define INF 1000000000
        int main()
        {
          FILE *fin,*fout;
           fin=fopen("data.in","rb");
            fout=fopen("data.out","wb");
        ....
        while(fscanf(fin,"%d",&x)==1)
        {...}
        fprintf(fout,....);
        fclose(fin);
        fclose(fout);
        ...
        }
      4. 步骤
        1. 先声明变量fin fout
        2. 把scanf print改为fscanf fprintf
        3. 第一个参数分别是 fin fout
        4. 最后要执行fclose关闭两个文件。
      5. 可以反复打开文件,而且想把它改为标准输入输出只需要使“fin=stdin”“fout=stdout”,不调用fopen fclose;
  • 相关阅读:
    linux运维学习
    2017年阿里巴巴三面经验
    Spring Boot:在Spring Boot中使用Mysql和JPA
    meshroom和alicevision在Ubuntu16上的安装过程
    ubuntu rm -rf ntfs 硬盘恢复
    python 脚本内部修改 LD_LIBRARY_PATH
    python uml 图
    tlmgr 相关
    ubuntu 安装 clangd 10.0.0
    zsh 快捷键
  • 原文地址:https://www.cnblogs.com/xuwanwei/p/10714127.html
Copyright © 2011-2022 走看看