1

简易秒表

代码

// Author : Weihao Long
// Created : 2018/03/15

#include <Windows.h>
#include <bits/stdc++.h>

using namespace std;

class Stopwatch {
public:
    Stopwatch(int h = 0, int m = 0, int s = 0) :hour(h), minute(m), second(s) {}
    void run() {
        while (true) {
            show();
            Sleep(1000);
            tick();
        }
    }
private:
    int hour, minute, second;
    void show() {
        printf("\r");
        printf("%02d:%02d:%02d", hour, minute, second);
    }
    void tick() {
        second += 1;
        if (second == 60) {
            second = 0;
            minute += 1;
            if (minute == 60) {
                minute = 0;
                hour += 1;
            }
            if (hour == 24) {
                hour = 0;
            }
        }
    }
};

int main() {
    Stopwatch c;
    c.run();
    return 0;
}

龙威昊
4 声望5 粉丝

下一篇 »
HDU 1896 Stones