zoukankan      html  css  js  c++  java
  • 简易计时器

    #include <stdio.h>

    #include <windows.h>

    typedef struct {

      int hour, minute, second;

    } TIME;

    void rationalize(TIME* t) {

      int sc = 0;

      t->second += sc;

      sc = t->second / 60;

      t->second %= 60;

      t->minute += sc;

      sc = t->minute / 60;

      t->minute %= 60;

      t->hour += sc;

      t->hour %= 24;

    }

    void input(TIME* t) {

      scanf("%d%d%d", &t->hour, &t->minute, &t->second);

      rationalize(t);

    }

    void print(TIME* t) {

      printf("%02d:%02d:%02d ", t->hour, t->minute, t->second);

    }

    void setTime(TIME* t, int hour, int min, int sec) {

      t->hour = hour;

      t->minute = min;

      t->second = sec;

    }

    void inc(TIME* t) {

      t->second++;

      if (t->second == 60) rationalize(t);

      Sleep(1000);

    }

    int main(int argc, char const* argv[]) {

      TIME t;

      setTime(&t, 10, 0, 0);

      rationalize(&t);

      int i;

      for (i = 0; i < 6000; i++) inc(&t), print(&t);

      return 0;

    }

  • 相关阅读:
    linux
    python(4)
    python(4)
    python(4)–yield实现异步
    python(4)-迭代器 和 生成器
    JavaScript函数参数问题
    文字垂直居中
    Window-document-javascript
    Java的StringTokenizer类
    Web应用与Spring MVC锁session
  • 原文地址:https://www.cnblogs.com/eastofeden/p/7376000.html
Copyright © 2011-2022 走看看