PAT (Basic Level) Practice (中文) 1026 程序运行时间

Posted learn-excel

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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
",h,m,s);
    return 0;
}
View Code
技术图片
#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
",h,m,s);
    return 0;
}
View Code

发现vs2010中没有round函数,但是这个题目需要四舍五入。

转换为时间的数字不是整数,而是浮点数。

以上是关于PAT (Basic Level) Practice (中文) 1026 程序运行时间的主要内容,如果未能解决你的问题,请参考以下文章