PAT乙级1026

题目链接

https://pintia.cn/problem-sets/994805260223102976/problems/994805295203598336

题解

就只有一个四舍五入需要注意一下,其他的没啥难度,都是简单的运算而已……

// PAT BasicLevel 1026
// https://pintia.cn/problem-sets/994805260223102976/problems/994805295203598336

#include <iostream>
using namespace std;

#define CLK_TCK 100

int main()
{
    // 获取C1和C2,并计算时间差(不足一秒进行四舍五入)
    int c1,c2;
    cin >> c1 >> c2;
    int time = (c2 - c1)*1.0/CLK_TCK+0.5;

    // 计算小时、分钟、秒
    int hour=time/3600;
    time%=3600;
    int min=time/60;
    int sec=time%60;

    // 按格式输出结果
    printf("%02d:%02d:%02d",hour,min,sec);

    //system("pause");
    return 0;
}

作者:@臭咸鱼

转载请注明出处:https://www.cnblogs.com/chouxianyu/

欢迎讨论和交流!


原文地址:https://www.cnblogs.com/chouxianyu/p/11318417.html