pat-basic-1026-Program Run time

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.