PAT (Basic Level) Practice (中文) 1026 程序运行时间
#include<stdio.h> #include<math.h> using namespace std; int main(){ int c1,c2,h,m,s; int c; scanf("%d %d",&c1,&c2); c = (c2-c1); h = c / (3600*100); m = c/ (60*100); m -= h * 60; s = round((c/100.0 - h * 3600 - m * 60)) ; printf("%02d:%02d:%02d\n",h,m,s); return 0; }
#include<stdio.h> #include<math.h> using namespace std; int main(){ int c1,c2,h,m; double s; int c; scanf("%d %d",&c1,&c2); c = (c2-c1); h = c / (3600*100); m = c/ (60*100); m -= h * 60; s = (c/100.0 - h * 3600 - m * 60); printf("%02d:%02d:%02.0f\n",h,m,s); return 0; }
发现vs2010中没有round函数,但是这个题目需要四舍五入。
转换为时间的数字不是整数,而是浮点数。