当前位置:网站首页>习题9-1 时间换算 (15 分)
习题9-1 时间换算 (15 分)
2022-06-11 22:19:00 【小言同学Y】
本题要求编写程序,以hh:mm:ss的格式输出某给定时间再过n秒后的时间值(超过23:59:59就从0点开始计时)。
输入格式:
输入在第一行中以hh:mm:ss的格式给出起始时间,第二行给出整秒数n(<60)。
输出格式:
输出在一行中给出hh:mm:ss格式的结果时间。
输入样例:
11:59:40
30
输出样例:
12:00:10
#include<stdio.h>
struct time{
int hour;
int minute;
int second;
};
int main(){
struct time t;
int sec,t1;
scanf("%d:%d:%d",&t.hour,&t.minute,&t.second);
scanf("%d",&sec);
t1=sec+t.second;
if(t1>=60){ //秒钟大于等于60,向前进位
t.second=t1-60;
t.minute++;
if(t.minute>=60){ //分钟大于等于60,向前进位
t.minute=t.minute-60;
t.hour++;
if(t.hour>=24){
t.hour-=24;
}
}
}else{
t.second=t1;
}
printf("%02d:%02d:%02d",t.hour,t.minute,t.second);
}总结:
- 此题只要清楚时钟、分钟、秒种之间进位的问题,就可以很容易解决;
- 注意输出格式的问题,用“%02d”的格式来输出。
边栏推荐
- Implementation of sequencelist sequence table
- Collection of articles and literatures related to R language (continuously updated)
- 图书管理系统
- FastAPI 5 - 常用请求及 postman、curl 使用(parameters,x-www-form-urlencoded, raw)
- 批改网高分短语&句型
- 如果重来一次高考,我要好好学数学!
- leetcode 中的位运算
- Huawei equipment configuration h-vpn
- How to view the installation date of the win system
- 926. 将字符串翻转到单调递增
猜你喜欢

超标量处理器设计 姚永斌 第2章 Cache --2.4 小节摘录

How to adjust the font blur of win10

超标量处理器设计 姚永斌 第2章 Cache --2.2 小节摘录

二叉树的基本操作与题型总结

Leetcode - day 2

Precision twist jitter

Learning bit segment (1)

BUUCTF(5)
![[Yu Yue education] calculus of Zhejiang University in autumn and winter 2021 (I) reference materials](/img/0a/58df3fd771d58c66245397d131fa53.png)
[Yu Yue education] calculus of Zhejiang University in autumn and winter 2021 (I) reference materials

How to view the installation date of the win system
随机推荐
大学三年应该这样过
电脑强制关机 oracle登录不上
leetcode 257. Binary Tree Paths 二叉树的所有路径(简单)
C language to achieve eight sorts (2)
R language book learning 03 "in simple terms R language data analysis" - Chapter 8 logistic regression model Chapter 9 clustering model
STM32 development note 113:ads1258 drive design - reading temperature value
Nmap performs analysis of all network segment IP survivals in host detection
机器学习之Logistic回归简单实例
C language implements eight sorts of sort merge sort
Basic operation and question type summary of binary tree
3.3 测试模块的命名规则
MATLAB点云处理(二十五):点云生成 DEM(pc2dem)
3.2 测试类的命名规则
Lecture de l'article dense Visual SLAM for RGB - D Cameras
swiper——单页面多轮播插件冲突解决方案
Why is the printer unable to print the test page
机器学习之线性回归简单实例
Custom implementation offsetof
Huawei equipment configuration hovpn
剑指offer数组题型总结篇