当前位置:网站首页>PAT 乙等 1026 程序运行时间
PAT 乙等 1026 程序运行时间
2022-06-23 04:11:00 【章鱼bro】
1026. 程序运行时间(15)
要获得一个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秒的时间四舍五入到秒。
输入样例:123 4577973输出样例:
12:42:59
注意四舍五入还有输出格式,不够10的要加零即可
代码
#include "stdio.h"
int main()
{
double begin,end; //存储开始和结束的计时点
double count;//每秒时钟打点个数
int time;//总秒数
int hour = 0,minute = 0,second = 0;
scanf("%lf",&begin);
scanf("%lf",&end);
count = end - begin;
time = (int)((count / 100) + 0.5);//四舍五入
hour = time / 3600;//计算小时
minute = time % 3600 / 60;
second = time % 60;
printf("%02d:%02d:%02d",hour, minute, second);
return 0;
}边栏推荐
- 树莓派assert初步使用练习
- 数字藏品——新的投资机遇
- Win11不能录制音频怎么办?Win11无法录入声音的解决方法
- Wechat applet: Puzzle toolbox
- TCP/IP 详解(第 2 版) 笔记 / 3 链路层 / 3.3 全双工, 节能, 自动协商机制, 802.1X 流控制 / 3.3.3 链路层流量控制
- The performance of nonstandard sprintf code in different platforms
- Alibaba cloud object storage oss+picgo+typera implements the construction map
- sprintf 格式代码使用不规范在不同平台下的表现
- Win11 app store keeps turning around solution
- 低成本5W无线充电器方案FS68001B简便充电芯片
猜你喜欢

C primer plus學習筆記 —— 2、常量與格式化IO(輸入/輸出)

Win11 app store keeps turning around solution

What if win11 cannot record audio? Solution of win11 unable to input sound

Opportunities and challenges of digital collections from the perspective of technology development team

Software design and Development Notes 2: serial port debugging tool based on QT design

软件设计开发笔记2:基于QT设计串口调试工具

runc 符号链接挂载与容器逃逸漏洞预警(CVE-2021-30465)

visdom的使用

数字藏品赋能实体产业释放了哪些利好?

Real MySQL interview question (30) -- shell real estate order analysis
随机推荐
Wechat applet: a new interesting test
Wechat applet: unfashionable love talk
Jvm: when a method is overloaded, the specific method to call is determined by the static type of the incoming parameter rather than the actual type of the parameter
runc 符号链接挂载与容器逃逸漏洞预警(CVE-2021-30465)
What does it mean to open more accounts? Why open more accounts? How to implement it safely?
Oracle异常
The author believes that the so-called industrial Internet is a process of deep integration of industry and the Internet
C primer plus learning notes - 2. Constant and formatted IO (input / output)
Jenkins installs and deploys and automatically builds and publishes jar applications
Implementation of MySQL custom sequence number
软件设计开发笔记2:基于QT设计串口调试工具
AHA C language Chapter 7 you can do more with it (talks 27-28)
opencv显示图像
低成本5W无线充电器方案FS68001B简便充电芯片
MySQL面试真题(二十八)——案例-通讯运营商指标分析
Jsonfield annotation in fastjson
STC 32-bit 8051 MCU development example tutorial I development environment construction
Build a gocd environment
Heimdall database proxy scale out 20 times
Implementation of pyGame music related functions