首页 > 试题广场 >

程序运行时间(15)

[编程题]程序运行时间(15)
  • 热度指数:19029 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32M,其他语言64M
  • 算法知识视频讲解
要获得一个C语言程序的运行时间,常用的方法是调用头文件time.h,其中提供了clock()函数,可以捕捉从程序开始运行到clock()被调用时所

耗费的时间。这个时间单位是clock tick,即“时钟打点”。同时还有一个常数CLK_TCK,给出了机器时钟每秒所走的时钟打点数。于是为了获

得一个函数f的运行时间,我们只要在调用f之前先调用clock(),获得一个时钟打点数C1;在f执行完成后再调用clock(),获得另一个时钟打点

数C2;两次获得的时钟打点数之差(C2-C1)就是f运行所消耗的时钟打点数,再除以常数CLK_TCK,就得到了以秒为单位的运行时间。



这里不妨简单假设常数CLK_TCK为100。现给定被测函数前后两次获得的时钟打点数,请你给出被测函数运行的时间。

输入描述:
输入在一行中顺序给出2个整数C1和C2。注意两次获得的时钟打点数肯定不相同,即C1 < C2,并且取值在[0, 107]


输出描述:
在一行中输出被测函数运行的时间。运行时间必须按照“hh:mm:ss”(即2位的“时:分:秒”)格式输出;不足1秒的时间四舍五入到秒。
示例1

输入

123 4577973

输出

12:42:59
A, B = [eval(i) for i in input().split()]
C = (B - A) / 100
C = int(C) if C - int(C) < 0.5 else int(C) + 1
second = C % 60
C //= 60
minite = C % 60
C //= 60
hour = C
print('{:0>2d}:{:0>2d}:{:0>2d}'.format(hour, minite, second))

发表于 2019-08-28 11:01:38 回复(0)
# -*- coding: utf-8
def round_x(num):
    x1, x2 = str(num).split('.')
    if int(x1)<int(num+0.5):
        return int(x1) + 1
    else:
        return int(x1)


def method():
    c1, c2 = map(int, input().split())
    c = round_x((c2 - c1) / 100)
    second, c = c % 60, c // 60
    minute, hour = c % 60, c // 60
    return '{:0>2}:{:0>2}:{:0>2}'.format(hour, minute, second)


if __name__ == '__main__':
    print(method())
发表于 2019-05-27 09:59:10 回复(0)
C1,C2 = map(int,input().split())
timeS = round((C2 - C1) / 100)
m,s = divmod(timeS,60)
h,m = divmod(m,60)
print (":".join(map(lambda c: str(c).rjust(2, "0"), [h, m, s])))

发表于 2019-03-08 09:17:46 回复(0)
try:
    while True:
        digitList = list(map(int,input().split()))
        secondsNum = int((digitList[1]-digitList[0])/100+0.5)
        hours,secondsNum = divmod(secondsNum,3600)
        minutes,seconds = divmod(secondsNum,60)
        print("%02d:%02d:%02d"%(hours,minutes,seconds))
except Exception:
    pass
编辑于 2018-09-21 17:43:51 回复(0)
 # 常数,机器时钟每秒所走的时钟打点数
CLK_TCK = 100

c1, c2 = input().split()
clock_tick_time = (int(c2) - int(c1)) // CLK_TCK
hh = clock_tick_time // 3600
mm = (clock_tick_time - hh * 3600) // 60
ss = clock_tick_time - hh * 3600 - mm * 60
print("{hh:02d}:{mm:02d}:{ss:02d}".format(hh=hh, mm=mm, ss=ss))

发表于 2018-03-30 23:39:25 回复(0)

python solution

c1, c2 = map(int, input().split())
#注意这里要四舍五入
seconds = round((c2 - c1) / 100)
#下面这两行是求对应的时、分、秒
m, s = divmod(seconds, 60)
h, m = divmod(m, 60)
#格式化输出
print (":".join(map(lambda c: str(c).rjust(2, "0"), [h, m, s])))
编辑于 2017-11-17 10:39:00 回复(1)
# coding:utf-8

a, b = raw_input().split(' ')
t = (int(b) - int(a) + 50) / 100
print '%02d:%02d:%02d' % (t / 3600, t % 3600 / 60, t % 60)
发表于 2017-04-25 19:25:06 回复(0)