嘿大家。我继续学习C++,并且我已经设置了将秒转换为格式化为“日,分和秒”的“挑战”。将秒转换为天,分和秒
例如:31600000 = 365天,46分40秒。
using namespace std;
const int hours_in_day = 24;
const int mins_in_hour = 60;
const int secs_to_min = 60;
long input_seconds;
cin >> input_seconds;
long seconds = input_seconds % secs_to_min;
long minutes = input_seconds/secs_to_min % mins_in_hour;
long days = input_seconds/secs_to_min/mins_in_hour/hours_in_day;
cout << input_seconds << " seconds = "
<< days << " days, "
<< minutes << " minutes, "
<< seconds << " seconds ";
return 0;
它的工作原理和正确答案来了,但在完成之后我看了看其他人如何解决了它,他们是不同的。我想知道如果我错过了什么。
谢谢,丹。
它有什么不同? – Mark 2010-03-10 18:41:40
天=时间/ 86400 小时=(时间/ 3600) - (天* 24) 分钟=(时间/ 60) - (天* 1440) - (小时* 60) 秒=时间模60 感谢。 – Dan 2010-03-10 18:42:35