PAT - Class B 1026 Program Run Time

1026. Program running time(15)

time limit
200 ms
memory limit
65536 kB
code length limit
8000 B
Judgment procedure
Standard
author
CHEN, Yue

To get the running time of a C language program, the common method is to call the header file time.h, which provides the clock() function, which can capture the time taken from the beginning of the program to the time when clock() is called. This time unit is clock tick, that is, "clock tick". There is also a constant CLK_TCK, which gives the number of clock ticks that the machine clock travels per second. So in order to get the running time of a function f, we only need to call clock() before calling f to get a clock ticking number C1; call clock() after the execution of f to get another clock ticking number C2; twice The difference between the obtained clock ticks (C2-C1) is the number of clock ticks consumed by f running, and then divided by the constant CLK_TCK to get the running time in seconds.

Here may simply assume that the constant CLK_TCK is 100. Now, given the number of clock ticks obtained before and after the function under test, please give the running time of the function under test.

Input format:

The input gives 2 integers C1 and C2 sequentially in one line. Note that the number of clock ticks obtained twice is definitely not the same, that is, C1 < C2, and the value is in [0, 10 7 ].

Output format:

Prints the time the function under test runs in one line. The elapsed time must be output in the format "hh:mm:ss" (ie, 2-digit "hour:minute:second"); times less than 1 second are rounded to the nearest second.

Input sample:
123 4577973
Sample output:
12:42:59

#include<cstdio>

using namespace std;

int main(){
	int a, b;
	scanf("%d %d", &a, &b);
	int x = ((b - a) % 100 < 50) ? (b - a) / 100 : (b - a) / 100 + 1; // rounding up...
	int h, m, s;
	s = x % 60;
	m = x / 60 % 60;
	h = x / 60 / 60;
	printf("%02d:%02d:%02d", h, m, s);
	return 0;
}


Guess you like

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