Pat乙级1026题——程序运行时间(Python)

PAT乙级 (Basic Level) 目录【Python解】已完结至1125 计算机编程能力考试(Programming Ability Test,简称PAT)是由。旨在培养和展现学生分析问题、解决问题和计算机程序设计的能力,计算机程序设计人才,并为企业选拔人才提供。 阅读详情

注意

  • 注意不足1秒的时间要四舍五入到秒,我使用的方法是round()

  • 时间输出注意高位补零,即%02d

代码如下

def time():
    content = map(int, raw_input().split(' '))
    CLK_TCK = 100
    if content[0] >= content[1]:
        return
    allSecond = round(float(content[1]- content[0]) / CLK_TCK)
    time = [0, 0, 0]
    i = 2
    while allSecond > 60:
        time[i] = allSecond % 60
        allSecond = allSecond / 60
        i = i - 1
    time[i] = allSecond % 60
    print "%02d:%02d:%02d"% (time[0], time[1], time[2])

if __name__ == '__main__':
    time()

测试结果

这里写图片描述

PAT乙级【Java题解合集】 学习完本专栏后,leetcode的简单题应该是没啥问题了,可以去做甲级的题目或者leetcode中等以上难度的题目继续修炼,后续博主会整理并更新算法修炼专栏,欢迎您的订阅!👉🏻算法修炼专栏👈🏻。 阅读详情

相关推荐

PAT (Basic Level) Practice 乙级1021-1030

PAT (Basic Level) Practice 乙级合集1021-1030

2301_80079117的博客 2798

【Python】PAT-1026 程序运行时间(AC)

题目 1026 程序运行时间 (15 分) 要获得一个 C 语言程序的运行时间,常用的方法是调用头文件 time.h,其中提供了 clock() 函数,可以捕捉从程序开始运行到 clock() 被调用时所耗费的时间。这个时间单位是 clock tick,即“时钟打点”。同时还有一个常数 CLK_TCK,给出了机器时钟每秒所走的时钟打点数。于是为了获得一个函数 f 的运行时间,我们只要在调用 f 之前先调用 clock(),获得一个时钟打点数 C1;在 f 执行完成后再调用 clock(),获得另一个时钟打点

夏2同学的博客 576

PAT乙级python编程练习(六)

PAT乙级python编程练习(六) PAT乙级python编程练习(六) 1026 程序运行时间 1027 打印沙漏 1028 人口普查 1029 旧键盘 1030 完美数列 方法一 方法二 1026 程序运行时间 要获得一个 C 语言程序的运行时间,常用的方法是调用头文件 time.h,其中提供了 clock() 函数,可以捕捉从程序开始运行到 clock() 被调用...

Hannah的博客 906

1026 程序运行时间(15 分)

题目: 要获得一个 C 语言程序的运行时间,常用的方法是调用头文件 time.h,其中提供了 clock() 函数,可以捕捉从程序开始运行到 clock() 被调用时所耗费的时间。这个时间单位是 clock tick,即“时钟打点”。同时还有一个常数 CLK_TCK,给出了机器时钟每秒所走的时钟打点数。于是为了获得一个函数 f 的运行时间,我们只要在调用 f 之前先调用 clock(),获得一个...

jmlyy666的博客 986

可优化-PAT (Basic Level) Practice Python解法 1026 程序运行时间(时间进位/四舍五入Tobe解决)

可优化-PAT (Basic Level) Practice Python解法 1026 程序运行时间(时间进位/四舍五入Tobe解决) c1, c2 = map(int,input().split()) time = (c2-c1)/100 hrs = time//3600#不要在这一步就int,后面进位操作会报错 min = (time%3600)//60 sec = (time%3600)%60 if sec >= 59.5: if min == 59: min = se

右置心脏 302

「PAT乙级真题解析」Basic Level 1026 程序运行时间 (问题分析+完整步骤+伪代码描述+提交通过代码)

题目给定两个整数, 设定这两个数的差/CLK_TCK(此题中值为100)为程序时间运行的总秒数。 要求将花费的时间从总秒数转成"小时:分钟:秒数"的形式输出.

过美好生活,做高效程序员 2911

PAT 乙级 1026 程序运行时间 python

PAT 乙级 1026 程序运行时间 python

m0_43424109的博客 279

【AUTOSAR-COM】Transmission Mode 和 Transfer Property

1.COM模块的基本概念 首先在描述Transmission Mode 和 Transfer Property之前,有必要对COM模块的基本处理有一个直观的理解,我所描述的和对概念理解的也不一定完全正确。 Signal:指的是通信协议中的,一条报文中所保存的若干信号。 I-PDU:至少在COM模块中,可以理解为一条报文。 上图是在CANdb软件中编辑一个报文的Layout的界面,可以很形象的将I-PDU对等为这里的一条Message,而Signal就是需要在Message中需要摆放的Signal

tim_hoven的博客 4635

【PAT_Python解】1026 程序运行时间

多学习其他大佬的AC代码!

新时代先锋的博客 879

从零开始用QP框架开发STM32:事件驱动编程实战指南(附状态机设计技巧)

本文详细介绍了如何使用QP框架在STM32上实现事件驱动编程,包括状态机设计技巧和嵌入式开发实践。通过对比传统前后台系统和RTOS,展示了QP框架在资源占用、实时性和代码可维护性方面的优势,并提供了从环境搭建到高级状态机设计的完整指南。

h6i7j8的博客 1173

【SPSS实战】手动实现Quade非参数协方差分析:从数据准备到结果解读

本文详细介绍了在SPSS中手动实现Quade非参数协方差分析的全过程。针对数据不满足正态性和方差齐性假设时,如何通过秩转换、回归调整残差,并最终利用Kruskal-Wallis检验完成组间比较。该方法为处理含协变量的非参数多组比较问题提供了清晰的实战解决方案,并探讨了其与标准Quade检验的异同及适用场景。

weixin_29306317的博客 356

1026. 程序运行时间(15)--Python

很简单的一道题,但是还是有些坑的 (1)测试点1:这个测试的是四舍五入是否正确,当然有些特例在测试的时候就没有测出来,不过大面上的四舍五入还是要正确的; (2)测试点4:这个就比较的坑了,我使用了python中的封装类,但是,好像不识别,就只能自己写了一个计算时分秒的方法,好在不是特别复杂,所以这个测试点就是看你的时分秒的格式是否正确了。 #import datetime '''程序运行时

baidu_38271024的博客 751

小土堆学习笔记1:Dataset类代码实践

上一页中反复提到“类”,这究竟是什么东西?按我的理解(肯定不准确也不正式),class类就是某一个东西的共性,而且是等待被确认的共性。比如每台手机都有它自己的品牌、框架、价格等等属性,class类正是这些尚不确定的属性;而一旦确认了这些属性,就能够确认这到底是一台什么型号什么状态的手机,在确认了全部属性后就知道,这是一台Apple 16 Pro Max。抽象的不确定的共性就是类,具体的确定的个性就是示例。这个共性可以被用于多个编程目的,只不过某一个具体的编程行为还有它自己的独特性。

qq_40525602的博客 1626

PAT乙级_1026 程序运行时间_Python_AC解法_无疑难点

本文介绍了PAT乙级1026题"程序运行时间"的Python解法。题目要求计算程序运行时间,将两个时钟打点数差值转换为时:分:秒格式输出。解题步骤包括:1)读取输入的两个打点数;2)计算差值并四舍五入取整;3)分别计算时、分、秒;4)按指定格式输出结果。作者指出本题无特殊难点,代码实现了基本功能,但可能存在变量命名不规范等问题,欢迎读者提供改进建议。

CongQianS1的博客 437

Microsemi Libero使用技巧11——CoreUARTAPB RX管脚分配时不显示

调用串口IP核CoreUARTAPB,并例化到顶层设计,发现UART_RX管脚在进行管脚分配时没有显示出来,最后发现是CoreAPB3总线IP核配置不对导致,改为如下配置后正常。

whik1194的博客 758

【Prometheus】prometheus结合cAdvisor监控docker容器运行状态,并且实现实时告警通知

Docker的监控,可以使用Docker自带的stats命令来获取当前主机上运行中的容器的资源使用情况。 例如:容器的CPU使用率、内存占用、网络IO以及磁盘IO等指标。

景天科技苑 6万+

PAT乙级合集——python实现(持续更新中~)

最近在巩固python编程能力,本文用于记录python实现的PAT乙级刷题索引,以及在刷题过程中总结的一些规则和经验~ 刷题建议:PAT乙级都是些简单的题目,如果是刷题的同学可以直接按照题号顺序刷即可~ 刷题笔记和规则整理: 合集: 乙级编号 标题 PAT 1001 害死人不偿命的(3n+1)猜想(15分) PAT 1002 写出这个数 (20分) PAT 1003 我要通过!(20分) PAT 1004 成绩排名 (20分) PAT 1005 继续(3n+1)猜想(25分

crayonjingjing的博客 1205

CMake入门教程【基础篇】CMake+Visual Studio2022构建C++项目

CMake+Visual Studio2022搭建C++环境

小鱼酱的博客 4971

PAT乙级_合集_Python_AC解法_已完结至1125题

本文是针对PAT乙级考试Python解题的优化指南。作者发现虽然多数题目能顺利通过,但部分代码在提交时会出现错误或超时,而PAT系统不提供详细反馈。现有的Python解题资料较少且部分存在效率问题。文章旨在记录解题过程中的卡点、优化方法和最终AC代码,为使用Python的考生提供参考。目前优先更新前50题中较难的题目,后续会逐步补充其他题目。每道题将详细讲解解题思路以弥补代码注释不足的问题,帮助读者理解优化过程。

CongQianS1的博客 861

Hermes接入IMA知识库全攻略:将知识库装进你的Hermes智能体

本文详细介绍了如何将IMA知识库功能接入Hermes Agent平台,实现一站式笔记管理和知识库操作。主要内容包括:获取IMA访问凭证、下载技能包、配置凭据(支持文件和环境变量两种方式)、验证配置有效性,以及实际应用演示(查询知识库列表、创建笔记并添加到知识库)。文章还提供了常见问题解决方案,如认证失败处理、版本更新等。通过该集成,用户可在Hermes中直接调用IMA的笔记创建、知识库管理等强大功能,提升工作效率。

小石头的专栏 641

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

PAT乙级 (Basic Level) python3语言实现代码(全120道)

PAT乙级 (Basic Level) Practice (中文)题目共120道。本文所有代码均用python3语言编写,除了11道题因为个别测试点超时未通过外,其他均通过。

梁山伯的专栏 937

精雕软件(JDpaint) 5.5 绿色版

精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版精雕软件(JDpaint) 5.5 绿色版

PAT 乙级1026 程序运行时间

要获得一个 C 语言程序的运行时间,常用的方法是调用头文件 time.h,其中提供了 clock() 函数,可以捕捉从程序开始运行到 clock() 被调用时所耗费的时间。于是为了获得一个函数 f 的运行时间,我们只要在调用 f 之前先调用 clock(),获得一个时钟打点数 C1;两次获得的时钟打点数之差 (C2-C1) 就是 f 运行所消耗的时钟打点数,再除以常数 CLK_TCK,就得到了以秒为单位的运行时间。现给定被测函数前后两次获得的时钟打点数,请你给出被测函数运行的时间。

qq_44063802的博客 611

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

【PAT】乙级练习题

题目描述 星际战争开展了100年之后,NowCoder终于破译了外星人的密码!他们的密码是一串整数,通过一张表里的信息映射成最终4位密码。表的规则是:n对应的值是矩阵X的n次方的左上角,如果这个数不足4位则用0填充,如果大于4位的则只输出最后4位。 |1 1|^n => |Xn …| |1 0| |… …| 例如n=2时, |1 1|^2 => |1 1| *...

Xechos 394

PAT乙级Python题单知识点及题解

核心知识点:# sort()和sorted(),key参数,reverse参数# 多关键字排序:使用元组作为key# 自定义比较函数:cmp_to_key# 基本排序lst.sort() # 原地排序sorted(lst) # 返回新列表# 多关键字排序(重点!

2302_79277225的博客 467

PAT 乙级(Python) #1026 程序运行时间 (15 分)

#1026 程序运行时间 (15 分) 代码展示: c1, c2 = list(map(eval,(input().split()))) # c1, c2 = 123, 4577973 CLK_TCK = 100 delta = (c2 - c1) / CLK_TCK hh = int(delta/3600) mm = int((delta - hh*3600) / 60) ss = delta - hh*3600 - mm*60 # ss=round(ss) if ss - int(ss) >=

敲代码的小风 330

浙大PAT 乙级(Basic Level) Practice 题解合集(全AC版)

写下这篇是为了记录一下在暑假这段时间里从零开始自解的PAT乙级基础题。

weixin_53024141的博客 1132
上一篇: Pat乙级1025题——反转链表(Python)一个非零返回,一个运行超时
下一篇: Pat乙级1027题——打印沙漏(Python)
coder_wu
博客等级 码龄8年 5粉丝 29原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值