• 2020 7 13 每日随笔


    今天完成小学期的第7个项目,也就是猜数字,并且及时,用到了time函数,了解了什么叫做多线程。明天研究链表

    代码:

    #include <iostream>
    #include <time.h>
    using namespace std;
    class game
    {
    public:
    int h,m,s,sum;
    void input(){cout<<"请输入游戏时间(时分秒):"<<endl;cin>>h>>m>>s;}
    void guess();
    game(){}
    ~game(){}
    };
    void game::guess ()
    {
    sum=h*3600+m*60+s;
    srand((int)time(0));
    int n;
    n=rand()%10000+1;
    time_t start,end;

    while(1)
    {
    start=time(NULL);
    cout<<"游戏开始!数字范围1~10000,游戏时间:"<<sum<<"s,时间耗尽前未猜出数字则输,猜出就赢"<<endl;
    while(1)
    {
    end=time(NULL);
    int a;
    cout<<"输入数字:"<<endl;
    cin>>a;
    if(a<n) {cout<<"低了哦!"<<endl;}
    else if(a>n) {cout<<"高了哦!"<<endl;}
    else {cout<<"恭喜你,你赢了!"<<endl;return;}
    if(end-start>=sum) {cout<<"时间到,游戏结束"<<endl;cout<<"这个数字是:"<<n<<endl;return ;}
    }
    }
    }
    int main()
    {
    game a;
    char b;
    for(;;)
    {
    cout<<"是否开始游戏:A 、是 B、否"<<endl;
    cin>>b;
    if(b=='A')
    {
    a.input ();
    a.guess ();
    break;
    }
    }
    return 0;
    }

  • 相关阅读:
    平衡树-SBT
    平衡树-Splay
    平衡树-Treap
    Placing Medals on a Binary Tree Gym
    The 2016 Asia Regional Contest, Tsukuba Quality of Check Digits Gym
    shift-and 算法初体验
    汇编
    6.828(1)准备工作
    硬件
    git操作
  • 原文地址:https://www.cnblogs.com/fuxw4971/p/13337218.html
Copyright © 2020-2023  润新知