C 1026 程序运行时间 (15 分)


原题

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

代码

#include 
using namespace std;

const int CLK_TCK=100;
int main() {
    long C1,C2,time;
    cin>>C1>>C2;
    time=(C2-C1)%CLK_TCK>=50?(C2-C1)/CLK_TCK+1:(C2-C1)/CLK_TCK;
    printf("%02d:%02d:%02d",time/60/60,time/60%60,time%60);
    return 0;
}

大佬对四舍五入处理,直接加50用得巧妙

#include 
using namespace std;
int main() {
    int a, b;
    cin >> a >> b;
    int n = ((b - a) + 50) / 100;
    int hour = n / 3600;
    n = n % 3600;
    int minute = n / 60, second = n % 60;
    printf("%02d:%02d:%02d", hour, minute, second);
    return 0;
}