The usual way to get the run time of a C program is to call the header file Time.h, which provides the clock () function, which captures the time it takes to get from the beginning of the program to the clock (). This unit of time is clock tick, which is called "clocking". There is also a constant clk_tck that gives the number of clock ticks per second that the machine clock is walking. So in order to get the running time of a function f, we just call clock () before calling F, get a clock count C1, then call Clock () after F execution completes, get another clock count C2; two times the difference of the number of clock ticks (C2-C1) is the number of clock ticks consumed by the F-run, divided by the constant Clk_tck, and the elapsed time in seconds is obtained.
Here's a simple assumption that the constant CLK_TCK is 100. Now given the number of clock ticks obtained two times before and after the measured function, please give the elapsed time of the measured function.
Input format:
Enter the order of 2 integers C1 and C1 in a row. Note that two times the number of clock hits must be different, namely C1 < C2, and the value is in [0, 107].
Output format:
Outputs the elapsed time of the measured function in a row. The run time must be output in the format "Hh:mm:ss" (That is, 2-bit "time: Seconds"), and less than 1 seconds is rounded to the second.
Input Sample:
123 4577973
Sample output:
12:42:59
Convert the difference of two integers to a time by dividing it by 100
There are two points to note, one for rounding, and two for the output format.
#include <bits/stdc++.h>using namespacestd;intMain () {intdata1, data2; intdif; CIN>> data1 >>data2; DIF= Data2-data1; if(DIF% ->= -) {dif= dif/ -+1; } Else{dif= dif/ -; } printf ("%02d:%02d:%02d", dif/3600, (dif%3600)/ -, dif% -); return 0;}
Capouis ' CODE
pat-basic-1026-Program Run time