zoukankan      html  css  js  c++  java
  • 学习进度条-第二周

    所花时间(包括上课)

    17小时

    代码量

    500行

    博客量

    写了3篇,阅读15篇+

    了解到的知识点

    文件读写

    基础知识,直接看代码吧

    示例程序:

    #include <fstream>
    #include <iostream>
    using namespace std;
     
    int main ()
    {
        
       char data[100];
     
       // 以写模式打开文件
       ofstream outfile;
       outfile.open("afile.dat");
     
       cout << "Writing to the file" << endl;
       cout << "Enter your name: "; 
       cin.getline(data, 100);
     
       // 向文件写入用户输入的数据
       outfile << data << endl;
     
       cout << "Enter your age: "; 
       cin >> data;
       cin.ignore();
       
       // 再次向文件写入用户输入的数据
       outfile << data << endl;
     
       // 关闭打开的文件
       outfile.close();
     
       // 以读模式打开文件
       ifstream infile; 
       infile.open("afile.dat"); 
     
       cout << "Reading from the file" << endl; 
       infile >> data; 
     
       // 在屏幕上写入数据
       cout << data << endl;
       
       // 再次从文件读取数据,并显示它
       infile >> data; 
       cout << data << endl; 
     
       // 关闭打开的文件
       infile.close();
     
       return 0;
    }
    

    随机数生成(真)

    C++ 库有一个名为 rand() 的函数,每次调用该函数都将返回一个非负整数。

    但是,该函数返回的数字其实是伪随机数。

    该算法需要一个起始值,称为种子,以生成数字。如果没有给出一个种子,那么它将在每次运行时产生相同的数字流。

    提供种子通过调用 srand(unsigned int seed) 函数完成

    time 函数返回从 1970 年 1 月 1 日午夜开始到现在逝去的秒数

    综上,随机数获取方法

        unsigned seed;  // Random generator seed
        // Use the time function to get a "seed” value for srand
        seed = time(0);
        srand(seed);
        // Now generate and print three random numbers
        cout << rand() << " " ;
        cout << rand() << " " ;
        cout << rand() << endl;
    

    动态规划

    如何理解动态规划,这里贴一段quora的高赞回答,具体实现可以参考网上的其他博客

    How should I explain dynamic programming to a 4-year-old?

    *writes down "1+1+1+1+1+1+1+1 =" on a sheet of paper*

    "What's that equal to?"

    *counting* "Eight!"

    *writes down another "1+" on the left*

    "What about that?"

    *quickly* "Nine!"

    "How'd you know it was nine so fast?"

    "You just added one more"

    "So you didn't need to recount because you remembered there were eight!*Dynamic Programming* is just a fancy way to say 'remembering stuff to save time later'"

    MarkDown排版

    这篇博客就是用MarkDown写的,知识点都在博客里了

  • 相关阅读:
    中国移动校园WLAN客户端及使用方法
    Win7 开启upnp服务,直接在网络中设置连接路由设备
    转载:迷你云 – 搭建自己的本地多人团队Dropbox 服务
    JLINK V8固件烧录指导
    实验室网站试运营期间的信息管理
    并非如你想象的那般强大,带你重新认识3D打印
    转:技术宅逆天了!如何从按键音中听出周鸿祎的手机号码
    南大学生破译周鸿祎电话获得互联网大佬青睐
    E430 加装固态硬盘(SSD)参考
    iptables_cacti_nagios
  • 原文地址:https://www.cnblogs.com/deepend/p/12384311.html
Copyright © 2011-2022 走看看