当前位置:网站首页>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;
}边栏推荐
- MySQL面试真题(二十六)——滴滴2020年笔试题
- Lihongyi, machine learning 5 Tips for neural network design
- How does win11 enable mobile hotspot? How to enable mobile hotspot in win11
- 华为软硬件生态圈成型,从根子上改变美国对软硬件体系的领导地位
- SIFT feature point extraction
- @jsonfield annotation in fastjson
- TCP/IP 详解(第 2 版) 笔记 / 3 链路层 / 3.4 网桥与交换机
- opencv显示图像
- 数字藏品——新的投资机遇
- [graduation season u; advanced technology Er] farewell to the confused self in the past two years. Regroup, junior I'm coming
猜你喜欢

Win11应用商店一直转圈解决办法

MySQL面试真题(二十二)——表连接后的条件筛选及分组筛选

A bit of knowledge - folding forging and Damascus steel

技术开发团队视角看到的数字藏品机遇与挑战

MDM data cleaning function development description

Cloud native architecture (04) -cncf

C prime plus notes d'apprentissage - 2, constantes et formatage io (I / o)

MySQL面试真题(二十五)——常见的分组比较场景

MySQL面试真题(二十三)——拼多多-球赛分析

数字藏品火热背后需要强大的技术团队支持 北方技术团队
随机推荐
MySQL面试真题(二十九)——案例-找到爱看的电影
数字藏品赋能实体产业释放了哪些利好?
What does the English letter PC mean? What does the Internet PC mean
高等数学(第七版)同济大学 习题1-7 个人解答
The performance of nonstandard sprintf code in different platforms
Shifu, the open source development platform of the Internet of things, is open for internal testing! Release of the first version of technical documents
Meteorological mapping software panoply tutorial (updated from time to time)
June 22, 2022: golang multiple choice question, what does the following golang code output? A:3; B:1; C:4; D: Compilation failed. package main import ( “fmt“ ) func mai
Cloud native architecture (04) -cncf
数字藏品——新的投资机遇
技能自检 | 想当测试Leader,这6项技能你会吗?
Real MySQL interview question (XXVIII) -- case - Analysis of indicators of communication operators
英文字母pc是什么意思,互联网的pc指的是什么
Redis缓存穿透解决方案-布隆过滤器
树莓派assert初步使用练习
MDM data cleaning function development description
Mobile power fast charging qc3.0 scheme chip ip5318 fast charging scheme
Markdown add background color to the picture
Wechat applet: future wife query generator
MySQL面试真题(二十四)——行列互换