问题:
解答:
#include <iostream>
using namespace std;
const int DAY_TO_HOUR = 24;
const int HOUR_TO_MIN = 60;
const int MIN_TO_SEC = 60;
int main()
{
long seconds = 0,record=0;
int days = 0, hours = 0, minutes=0;
cout << "请输入秒数:";
cin >> seconds;
record = seconds;
days = seconds / (MIN_TO_SEC * HOUR_TO_MIN * DAY_TO_HOUR);
seconds = seconds % (MIN_TO_SEC * HOUR_TO_MIN * DAY_TO_HOUR);
hours = seconds / (MIN_TO_SEC * HOUR_TO_MIN);
seconds= seconds % (MIN_TO_SEC * HOUR_TO_MIN);
minutes = seconds / MIN_TO_SEC;
seconds = seconds % MIN_TO_SEC;
cout << record << "秒 = " << days << "天" << hours << "时" << minutes << "分" << seconds << "秒" << endl;
return 0;
}
运行结果:
考查点:
- 求余操作
注意:
- 注意秒数姚不断的变化,越来越少.
又是单位转化的题…
2024年8月23日20:09:39