PATB 1026 Program Run Time

insert image description here
Inscription

This question mainly involves rounding. If we want to round the result of (c2-c1)/100, then first let the result of (c2-c1)/100 be a floating point type and then add 0.5 at the end Cast the type to int. If c2 and c1 are both integer types, the result is naturally the number before the decimal point after the quotient, which is an integer type, so here we can define c1 and c2 as floating-point types, or define them again An intermediate variable that modifies 100 to 100.0 so that the result will be automatically up-converted.

#include <iostream>

using namespace std;

int main()
{
    
    
    double c1,c2;
    int h,m,s,newNum;
    scanf("%lf %lf",&c1,&c2);
    newNum=int((c2-c1)/100+0.5);
    s=newNum%60,newNum/=60;
    m=newNum%60,h=newNum/60;
    printf("%02d:%02d:%02d\n",h,m,s);
    return 0;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325349134&siteId=291194637