将秒转换为天,小时,分钟,秒。

第一感觉,想到的最笨方法。哈哈。



#include 
#include 
using namespace std;

int main(){
    
    long long time = 0;
    cout << "Input the total seconds:" << endl;
    cin >> time;
    long long day = time / 86400;
    long long hour = (time - day*86400) / 3600;
    long long minute = (time - day*86400 - hour*3600) / 60;
    long long second = (time - day*86400 - hour*3600 - minute * 60);
    cout << time << " seconds = " << day << " days " << hour << " hours " << minute << " minutes " << second << " seconds.";
    return 0;
}

不解释拉哈。

你可能感兴趣的:(C++Primer)