Program Run time

Source: Internet
Author: User

Links: http://www.nowcoder.com/pat/6/problem/4052

Title Description
To get the run time of a C program, a common method is to call the header file Time.h, which provides the clock () function, which can catch from the beginning of the program run to clock () is called when the

Time spent. 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 obtain

The run time of a function f, we just call clock () before calling F, get a clock C1 number, and then call Clock () to get another clock dot after F execution is complete

Number C2; The difference in the number of clock ticks obtained by two times (C2-C1) is the number of clock ticks consumed by the F operation, divided by the constant Clk_tck, and the elapsed time in seconds.



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 Description:
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 values in [0, 107]



Output Description:
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 Example:
123 4577973

Output Example:
12:42:59

Idea: The topic is very simple, as long as a good "rounding" calculation, it can be.
"Rounding": double A = 1.2; A + = 0.5; Floor[a] = 1;
Double b = 1.5; B + = 0.5; FLOOR[B] = 2;
Floor (x): takes the largest integer not greater than X (the largest integer less than or equal to X)
Ceil (x): Takes the smallest integer not less than x (the smallest integer greater than or equal to X)
1#include"iostream"2#include <iomanip>3#include <string.h>4#include <string>5#include <vector>6#include <cmath>7#include <cctype>8#include <algorithm>9 using namespacestd;Ten  One intMain () A { -     intC1, C2; -CIN &GT;&GT;C1 >>C2; the     intC3; -     if(C1 >C2) -     { -C3 =C1; +C1 =C2; -C2 =C3; +     } AC3 = C2-C1; atC3 = Floor (c3*1.0/( -*1.0))+0.5); -     intH = c3/3600; -     intm = (c3-h*3600)/ -; -     ints = (c3-h*3600-m* -); -     if(H <Ten) -     { incout <<0<

":"; - } to Elsecout <

":"; + if(M <Ten) - { thecout <<0<<m <<":"; * } $ Elsecout <<m <<":";Panax Notoginseng if(S <Ten) - { thecout <<0<<s <<Endl; + } A Elsecout <<s <<Endl; the return 0; +}

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.