给定秒数 seconds ,把秒转化成小时、分钟和秒。
数据范围:
int main()
{
int t,h,m,s={0};
scanf("%d",&t);
h=t/3600;
m=t%3600/60;
s=t%60;
printf("%d %d %d",h,m,s);
return 0;
}
int main() { int seconds = 0; int minute = 0; int hour = 0; scanf("%d", &seconds); minute = seconds / 60; //求总的分钟 minute = minute % 60; //求显示的分钟,不能超过60分 hour = seconds / 3600; //求总的小时 hour = hour % 24; //求显示的小时,不能超过24个小时 seconds = seconds % 60; //求余下的秒数 printf("%d %d %d", hour, minute, seconds); return 0; }
#include <stdio.h> #define SEC 1 #define MIN (SEC * 60) #define HOUR (MIN * 60) typedef long int int64_t; int main(void) { int64_t sec_input; scanf("%ld", &sec_input); int64_t hour = sec_input / HOUR; int64_t min = sec_input % HOUR / MIN; int64_t sec = sec_input % MIN; printf("%ld %ld %ld", hour, min, sec); return 0; }