PAT_B_1026 running time

Subject description:

To obtain a C language program running time, commonly used method is to call time.h header file, which provides a clock () function can be invoked when the capture time it takes to start running the program from a clock (). This time unit is clock tick, or "dot clock." At the same time there is a constant CLK_TCK, given clock hit points per second machine clock go. So in order to get a run-time function f, we just call first before calling f clock (), to obtain a clock hit points C1; call the clock after the completion of the implementation of the f (), get another clock hit points C2; twice points of difference beat clock obtained (C2-C1) is consumed by the operation of the clock f hit points, for CLK_TCK then divided by a constant, to get a running time in units of seconds. 
Here it might simply assumed constant CLK_TCK 100. Now hit points to the clock function measured before and after the two-time given, please give you time to run the test function. 
Input format: 
input two integers gives C1 and C2 sequence in a row. Note that the obtained two clock certainly not hit the same number of points, i.e. C1 <C2, and the value of [0, 10 ^ 7]. 
Output Format: 
output time measured function to run in a row. Run time must follow hh: output format (i.e., 2 seconds of:: min); less than 1 second time rounded to the second: mm ss. 
Sample input: 
1234577973 
Output Sample: 
12:42:59

I AC Code:

// PAT_1026_Time

# include <stdio.h>
# include <stdlib.h>

int main(void)
{
	int N1, N2;
	int hh, mm, ss, flag; 
	scanf("%d",&N1);
	scanf("%d",&N2);
	
	// 看是否四舍五入 
	flag = (N2-N1)%100;
	if (flag <= 49)
	{
		ss = (N2-N1)/100;
	}
	else
		ss = (N2-N1)/100+1;
	
	// 计算小时 
	hh = ss/3600; 
	ss = ss - hh*3600;
	mm = ss/60;
	ss = ss - mm*60;
		
	if (hh<10)
	{
		printf("0");
	}
		printf("%d:",hh);
		
	if (mm<10)
	{
		printf("0");
	}
		printf("%d:",mm);
	if (ss<10)
	{
		printf("0");
	}
		printf("%d",ss);
	
	return 0;
}

RRR

Guess you like

Origin www.cnblogs.com/Robin5/p/11243706.html